|
4 | 4 | using System.Globalization; |
5 | 5 | using System.Linq; |
6 | 6 | using System.Reflection; |
| 7 | +using System.Text; |
7 | 8 | using System.Text.RegularExpressions; |
8 | 9 |
|
9 | 10 | namespace CodingSeb.ExpressionEvaluator |
@@ -92,7 +93,7 @@ private enum IfBlockEvaluatedState |
92 | 93 |
|
93 | 94 | #region Dictionaries declarations (Primary types, number suffix, escaped chars, operators management, default vars and functions) |
94 | 95 |
|
95 | | - private Dictionary<string, Type> primaryTypesDict = new Dictionary<string, Type>() |
| 96 | + private static readonly Dictionary<string, Type> primaryTypesDict = new Dictionary<string, Type>() |
96 | 97 | { |
97 | 98 | { "object", typeof(object) }, |
98 | 99 | { "string", typeof(string) }, |
@@ -418,7 +419,6 @@ public bool OptionCaseSensitiveEvaluationActive |
418 | 419 | { |
419 | 420 | optionCaseSensitiveEvaluationActive = value; |
420 | 421 | Variables = Variables; |
421 | | - primaryTypesDict = new Dictionary<string, Type>(primaryTypesDict, StringComparerForCasing); |
422 | 422 | operatorsDictionary = new Dictionary<string, ExpressionOperator>(operatorsDictionary, StringComparerForCasing); |
423 | 423 | defaultVariables = new Dictionary<string, object>(defaultVariables, StringComparerForCasing); |
424 | 424 | simpleDoubleMathFuncsDictionary = new Dictionary<string, Func<double, double>>(simpleDoubleMathFuncsDictionary, StringComparerForCasing); |
@@ -2185,7 +2185,7 @@ private Type GetTypeByFriendlyName(string typeName, bool tryWithNamespaceInclude |
2185 | 2185 | { |
2186 | 2186 | typeName = primaryTypesRegex.Replace(typeName, delegate (Match match) |
2187 | 2187 | { |
2188 | | - return primaryTypesDict[match.Value].ToString(); |
| 2188 | + return primaryTypesDict[match.Value.ManageCasing(OptionCaseSensitiveEvaluationActive)].ToString(); |
2189 | 2189 | }); |
2190 | 2190 |
|
2191 | 2191 | result = Type.GetType(typeName, false, true); |
@@ -2233,34 +2233,74 @@ private static object ChangeType(object value, Type conversionType) |
2233 | 2233 | return Convert.ChangeType(value, conversionType); |
2234 | 2234 | } |
2235 | 2235 |
|
| 2236 | + //private string GetCodeUntilEndOfString(string subExpr, Match stringBeginningMatch) |
| 2237 | + //{ |
| 2238 | + // Match codeUntilEndOfStringMatch = stringBeginningMatch.Value.Contains("$") ? endOfStringWithDollar.Match(subExpr) : endOfStringWithoutDollar.Match(subExpr); |
| 2239 | + // string result = subExpr; |
| 2240 | + |
| 2241 | + // if (codeUntilEndOfStringMatch.Success) |
| 2242 | + // { |
| 2243 | + // if (codeUntilEndOfStringMatch.Value.EndsWith("\"")) |
| 2244 | + // { |
| 2245 | + // result = codeUntilEndOfStringMatch.Value; |
| 2246 | + // } |
| 2247 | + // else if (codeUntilEndOfStringMatch.Value.EndsWith("{") && codeUntilEndOfStringMatch.Length < subExpr.Length) |
| 2248 | + // { |
| 2249 | + // if (subExpr[codeUntilEndOfStringMatch.Length] == '{') |
| 2250 | + // { |
| 2251 | + // result = codeUntilEndOfStringMatch.Value + "{" |
| 2252 | + // + GetCodeUntilEndOfString(subExpr.Substring(codeUntilEndOfStringMatch.Length + 1), stringBeginningMatch); |
| 2253 | + // } |
| 2254 | + // else |
| 2255 | + // { |
| 2256 | + // string interpolation = GetCodeUntilEndOfStringInterpolation(subExpr.Substring(codeUntilEndOfStringMatch.Length)); |
| 2257 | + // result = codeUntilEndOfStringMatch.Value + interpolation |
| 2258 | + // + GetCodeUntilEndOfString(subExpr.Substring(codeUntilEndOfStringMatch.Length + interpolation.Length), stringBeginningMatch); |
| 2259 | + // } |
| 2260 | + // } |
| 2261 | + // } |
| 2262 | + |
| 2263 | + // return result; |
| 2264 | + //} |
| 2265 | + |
2236 | 2266 | private string GetCodeUntilEndOfString(string subExpr, Match stringBeginningMatch) |
2237 | 2267 | { |
2238 | 2268 | Match codeUntilEndOfStringMatch = stringBeginningMatch.Value.Contains("$") ? endOfStringWithDollar.Match(subExpr) : endOfStringWithoutDollar.Match(subExpr); |
2239 | | - string result = subExpr; |
| 2269 | + StringBuilder result = new StringBuilder(); |
2240 | 2270 |
|
2241 | 2271 | if (codeUntilEndOfStringMatch.Success) |
2242 | 2272 | { |
2243 | 2273 | if (codeUntilEndOfStringMatch.Value.EndsWith("\"")) |
2244 | 2274 | { |
2245 | | - result = codeUntilEndOfStringMatch.Value; |
| 2275 | + result.Append(codeUntilEndOfStringMatch.Value); |
2246 | 2276 | } |
2247 | 2277 | else if (codeUntilEndOfStringMatch.Value.EndsWith("{") && codeUntilEndOfStringMatch.Length < subExpr.Length) |
2248 | 2278 | { |
2249 | 2279 | if (subExpr[codeUntilEndOfStringMatch.Length] == '{') |
2250 | 2280 | { |
2251 | | - result = codeUntilEndOfStringMatch.Value + "{" |
2252 | | - + GetCodeUntilEndOfString(subExpr.Substring(codeUntilEndOfStringMatch.Length + 1), stringBeginningMatch); |
| 2281 | + result.Append(codeUntilEndOfStringMatch.Value); |
| 2282 | + result.Append("{"); |
| 2283 | + result.Append(GetCodeUntilEndOfString(subExpr.Substring(codeUntilEndOfStringMatch.Length + 1), stringBeginningMatch)); |
2253 | 2284 | } |
2254 | 2285 | else |
2255 | 2286 | { |
2256 | 2287 | string interpolation = GetCodeUntilEndOfStringInterpolation(subExpr.Substring(codeUntilEndOfStringMatch.Length)); |
2257 | | - result = codeUntilEndOfStringMatch.Value + interpolation |
2258 | | - + GetCodeUntilEndOfString(subExpr.Substring(codeUntilEndOfStringMatch.Length + interpolation.Length), stringBeginningMatch); |
| 2288 | + result.Append(codeUntilEndOfStringMatch.Value); |
| 2289 | + result.Append(interpolation); |
| 2290 | + result.Append(GetCodeUntilEndOfString(subExpr.Substring(codeUntilEndOfStringMatch.Length + interpolation.Length), stringBeginningMatch)); |
2259 | 2291 | } |
2260 | 2292 | } |
| 2293 | + else |
| 2294 | + { |
| 2295 | + result.Append(subExpr); |
| 2296 | + } |
| 2297 | + } |
| 2298 | + else |
| 2299 | + { |
| 2300 | + result.Append(subExpr); |
2261 | 2301 | } |
2262 | 2302 |
|
2263 | | - return result; |
| 2303 | + return result.ToString(); |
2264 | 2304 | } |
2265 | 2305 |
|
2266 | 2306 | private string GetCodeUntilEndOfStringInterpolation(string subExpr) |
|
0 commit comments