Skip to content

Commit 8bd62db

Browse files
committed
Some start of stuffs
1 parent 1ca1ddd commit 8bd62db

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ public void TypeTesting(string expression, Type type)
868868
[TestCase("List(\"hello\", \"bye\").Select(x => x.ToUpper()).ToList().FluidAdd(\"test\")[1]", ExpectedResult = "BYE", Category = "Complex expression,Fluid Functions")]
869869
[TestCase("List(\"hello\", \"bye\").Select(x => x.ToUpper()).ToList().FluidAdd(\"test\")[2]", ExpectedResult = "test", Category = "Complex expression,Fluid Functions")]
870870
[TestCase("List(\"hello\", \"bye\").Select(x => x.ToUpper()).ToList().FluidAdd(\"test\")[2]", ExpectedResult = "test", Category = "Complex expression,Fluid Functions")]
871-
[TestCase("$\"https://www.google.ch/search?q={System.Net.WebUtility.UrlEncode(\"test of request with url encode() ?\")}\"", ExpectedResult = "https://www.google.ch/search?q=test+of+request+with+url+encode()+%3F", Category = "Complex expression,Inline namespace")]
871+
[TestCase("$\"https://www.google.com/search?q={System.Net.WebUtility.UrlEncode(\"test of request with url encode() ?\")}\"", ExpectedResult = "https://www.google.com/search?q=test+of+request+with+url+encode()+%3F", Category = "Complex expression,Inline namespace")]
872872
#endregion
873873

874874
#endregion

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ private enum TryBlockEvaluatedState
237237
{
238238
new Dictionary<ExpressionOperator, Func<dynamic, dynamic, object>>()
239239
{
240-
{ExpressionOperator.Indexing, (dynamic left, dynamic right) => left is IDictionary<string,object> dictionaryLeft ? dictionaryLeft[right] : left[right] },
240+
{ExpressionOperator.Indexing, (dynamic left, dynamic right) => {
241+
return left is IDictionary<string,object> dictionaryLeft ? dictionaryLeft[right] : left[right];
242+
}
243+
},
241244
{ExpressionOperator.IndexingWithNullConditional, (dynamic left, dynamic right) => left is IDictionary<string,object> dictionaryLeft ? dictionaryLeft[right] : left?[right] },
242245
},
243246
new Dictionary<ExpressionOperator, Func<dynamic, dynamic, object>>()
@@ -486,29 +489,6 @@ private StringComparer StringComparerForCasing
486489
/// </summary>
487490
public bool OptionFluidPrefixingActive { get; set; } = true;
488491

489-
/// <summary>
490-
/// if <c>true</c> allow to create instance of object with the C# syntax new ClassName(...).
491-
/// if <c>false</c> unactive this functionality.
492-
/// By default : true
493-
/// </summary>
494-
public bool OptionNewKeywordEvaluationActive { get; set; } = true;
495-
496-
/// <summary>
497-
/// if <c>true</c> allow the use of inline namespace (Can be slow, and is less secure).
498-
/// if <c>false</c> unactive inline namespace (only namespaces in Namespaces list are available).
499-
/// By default : true
500-
/// </summary>
501-
public bool OptionInlineNamespacesEvaluationActive
502-
{
503-
get { return optionInlineNamespacesEvaluationActive; }
504-
set
505-
{
506-
optionInlineNamespacesEvaluationActive = value;
507-
instanceCreationWithNewKeywordRegex = new Regex(InstanceCreationWithNewKeywordRegexPattern, (optionCaseSensitiveEvaluationActive ? RegexOptions.None : RegexOptions.IgnoreCase));
508-
castRegex = new Regex(CastRegexPattern, (optionCaseSensitiveEvaluationActive ? RegexOptions.None : RegexOptions.IgnoreCase));
509-
}
510-
}
511-
512492
private Func<ExpressionEvaluator, List<string>, object> newMethodMem;
513493

514494
/// <summary>
@@ -534,6 +514,29 @@ public bool OptionNewFunctionEvaluationActive
534514
}
535515
}
536516

517+
/// <summary>
518+
/// if <c>true</c> allow to create instance of object with the C# syntax new ClassName(...).
519+
/// if <c>false</c> unactive this functionality.
520+
/// By default : true
521+
/// </summary>
522+
public bool OptionNewKeywordEvaluationActive { get; set; } = true;
523+
524+
/// <summary>
525+
/// if <c>true</c> allow the use of inline namespace (Can be slow, and is less secure).
526+
/// if <c>false</c> unactive inline namespace (only namespaces in Namespaces list are available).
527+
/// By default : true
528+
/// </summary>
529+
public bool OptionInlineNamespacesEvaluationActive
530+
{
531+
get { return optionInlineNamespacesEvaluationActive; }
532+
set
533+
{
534+
optionInlineNamespacesEvaluationActive = value;
535+
instanceCreationWithNewKeywordRegex = new Regex(InstanceCreationWithNewKeywordRegexPattern, (optionCaseSensitiveEvaluationActive ? RegexOptions.None : RegexOptions.IgnoreCase));
536+
castRegex = new Regex(CastRegexPattern, (optionCaseSensitiveEvaluationActive ? RegexOptions.None : RegexOptions.IgnoreCase));
537+
}
538+
}
539+
537540
/// <summary>
538541
/// if <c>true</c> allow to call static methods on classes.
539542
/// if <c>false</c> unactive this functionality.

TryWindow/MainWindow.xaml.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Diagnostics;
55
using System.IO;
6+
using System.Linq;
67
using System.Reflection;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -102,9 +103,20 @@ private async void CalculateButton_Click(object sender, RoutedEventArgs e)
102103

103104
private void Evaluator_EvaluateVariable(object sender, VariableEvaluationEventArg e)
104105
{
105-
if(e.This != null && e.Name.Equals("Json"))
106+
if (e.This != null)
106107
{
107-
e.Value = JsonConvert.SerializeObject(e.This);
108+
if (e.Name.Equals("Json"))
109+
{
110+
e.Value = JsonConvert.SerializeObject(e.This);
111+
}
112+
else if (e.Name.Equals("MethodsNames"))
113+
{
114+
e.Value = JsonConvert.SerializeObject(e.This.GetType().GetMethods().Select(m => m.Name));
115+
}
116+
else if (e.Name.Equals("PropertiesNames"))
117+
{
118+
e.Value = JsonConvert.SerializeObject(e.This.GetType().GetProperties().Select(m => m.Name));
119+
}
108120
}
109121
}
110122

0 commit comments

Comments
 (0)