Skip to content

Commit 517fa10

Browse files
committed
Correction of Int32 in caseinsensitive + Simplify primarytypes detection
1 parent a5d2bdb commit 517fa10

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,15 @@ ExpressionEvaluator evaluatorForMethodArgs()
24742474
.Returns(typeof(List<Regex>))
24752475
.SetCategory("Bug resolution");
24762476

2477+
yield return new TestCaseData(new ExpressionEvaluator()
2478+
{
2479+
OptionCaseSensitiveEvaluationActive = false
2480+
}
2481+
, "Int32.Parse(\"2\")"
2482+
, null)
2483+
.Returns(2)
2484+
.SetCategory("Bug resolution");
2485+
24772486
#region For bug #65
24782487
var Persons = new List<Person2>() { new Person2() { Code = "QT00010", Name = "Pedrito", Number = 11.11m },
24792488
new Person2() { Code = "QT00011", Name = "Pablito", Number = 12.11m }};

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public partial class ExpressionEvaluator
2929
{
3030
#region Regex declarations
3131

32-
protected const string primaryTypesRegexPattern = @"(?<=^|[^\p{L}_])(?<primaryType>object|string|bool[?]?|byte[?]?|char[?]?|decimal[?]?|double[?]?|short[?]?|int[?]?|long[?]?|sbyte[?]?|float[?]?|ushort[?]?|uint[?]?|ulong[?]?|void)(?=[^a-zA-Z_]|$)";
33-
3432
protected static readonly Regex varOrFunctionRegEx = new Regex(@"^((?<sign>[+-])|(?<prefixOperator>[+][+]|--)|(?<varKeyword>var)\s+|(?<dynamicKeyword>dynamic)\s+|((?<nullConditional>[?])?(?<inObject>\.))?)(?<name>[\p{L}_](?>[\p{L}_0-9]*))(?>\s*)((?<assignationOperator>(?<assignmentPrefix>[+\-*/%&|^]|<<|>>|\?\?)?=(?![=>]))|(?<postfixOperator>([+][+]|--)(?![\p{L}_0-9]))|((?<isgeneric>[<](?>([\p{L}_](?>[\p{L}_0-9]*)|(?>\s+)|[,\.])+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?<isfunction>[(])?))", RegexOptions.IgnoreCase | RegexOptions.Compiled);
3533

3634
protected const string numberRegexOrigPattern = @"^(?<sign>[+-])?([0-9][0-9_{1}]*[0-9]|\d)(?<hasdecimal>{0}?([0-9][0-9_]*[0-9]|\d)(e[+-]?([0-9][0-9_]*[0-9]|\d))?)?(?<type>ul|[fdulm])?";
@@ -3929,6 +3927,11 @@ protected virtual Type GetTypeByFriendlyName(string typeName, string genericType
39293927
typeName = typeName.Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("\n", "");
39303928
genericTypes = genericTypes.Replace(" ", "").Replace("\t", "").Replace("\r", "").Replace("\n", "");
39313929

3930+
if (primaryTypesDict.ContainsKey(OptionCaseSensitiveEvaluationActive ? typeName : typeName.ToLower()))
3931+
{
3932+
result = primaryTypesDict[OptionCaseSensitiveEvaluationActive ? typeName : typeName.ToLower()];
3933+
}
3934+
39323935
if (CacheTypesResolutions && (TypesResolutionCaching?.ContainsKey(typeName + genericTypes) ?? false))
39333936
{
39343937
result = TypesResolutionCaching[typeName + genericTypes];
@@ -3946,14 +3949,6 @@ protected virtual Type GetTypeByFriendlyName(string typeName, string genericType
39463949
result = Type.GetType(typeName + formatedGenericTypes, false, !OptionCaseSensitiveEvaluationActive);
39473950
}
39483951

3949-
if (result == null)
3950-
{
3951-
typeName = Regex.Replace(typeName, primaryTypesRegexPattern,
3952-
(Match match) => primaryTypesDict[OptionCaseSensitiveEvaluationActive ? match.Value : match.Value.ToLower()].ToString(), optionCaseSensitiveEvaluationActive ? RegexOptions.None : RegexOptions.IgnoreCase);
3953-
3954-
result = Type.GetType(typeName, false, !OptionCaseSensitiveEvaluationActive);
3955-
}
3956-
39573952
if (result == null)
39583953
{
39593954
result = Types.ToList().Find(type => type.Name.Equals(typeName, StringComparisonForCasing) || type.FullName.StartsWith(typeName + ","));

TryWindow/MainWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<WrapPanel>
2929
<CheckBox x:Name="NeedSemicolonAtTheEndCheckBox"
3030
Content="Need semicolon [;] At the end" />
31+
<CheckBox x:Name="CaseSensitiveCheckBox"
32+
Content="Case sensitive"
33+
IsChecked="True"/>
3134
</WrapPanel>
3235

3336
<Button x:Name="CalculateButton" Content="_Execute" IsDefault="True" Click="CalculateButton_Click" />

TryWindow/MainWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private async void CalculateButton_Click(object sender, RoutedEventArgs e)
3939
ExpressionEvaluator evaluator = new ExpressionEvaluator()
4040
{
4141
OptionScriptNeedSemicolonAtTheEndOfLastExpression = NeedSemicolonAtTheEndCheckBox.IsChecked.GetValueOrDefault(),
42+
OptionCaseSensitiveEvaluationActive = CaseSensitiveCheckBox.IsChecked.GetValueOrDefault()
4243
};
4344

4445
if (UseCachesCheckbox.IsChecked ?? false)

0 commit comments

Comments
 (0)