Skip to content

Commit 6691da5

Browse files
authored
Merge pull request #8 from codingseb/dev
Dev
2 parents cbeec9f + 5f1d9a6 commit 6691da5

File tree

5 files changed

+34
-24
lines changed

5 files changed

+34
-24
lines changed

CodingSeb.ExpressionEvaluator.Tests/Properties/AssemblyInfo.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
[assembly: AssemblyTitle("CodingSeb.ExpressionEvaluator.Tests")]
65
[assembly: AssemblyDescription("")]
76
[assembly: AssemblyConfiguration("")]
8-
[assembly: AssemblyCompany("EMP/PTM")]
7+
[assembly: AssemblyCompany("Coding Seb")]
98
[assembly: AssemblyProduct("CodingSeb.ExpressionEvaluator.Tests")]
10-
[assembly: AssemblyCopyright("Copyright © EMP/PTM 2018")]
9+
[assembly: AssemblyCopyright("Copyright © Coding Seb 2018")]
1110
[assembly: AssemblyTrademark("")]
1211
[assembly: AssemblyCulture("")]
1312

CodingSeb.ExpressionEvaluator/CodingSeb.ExpressionEvaluator.nuspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>CodingSeb.ExpressionEvaluator</id>
@@ -10,9 +10,9 @@
1010
<projectUrl>https://github.com/codingseb/ExpressionEvaluator</projectUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>A Simple Math and Pseudo C# Expression Evaluator in One C# File</description>
13-
<tags>evaluation math expression-evaluator expression parser eval evaluate fluid</tags>
13+
<tags>evaluation math expression-evaluator expression parser eval evaluate fluid C# calculation execute</tags>
1414
</metadata>
1515
<files>
1616
<file src="bin\Release\CodingSeb.ExpressionEvaluator.dll" target="lib\net45\CodingSeb.ExpressionEvaluator.dll" />
1717
</files>
18-
</package>
18+
</package>

CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs

+25-14
Original file line numberDiff line numberDiff line change
@@ -473,35 +473,46 @@ public ExpressionEvaluator(Dictionary<string, object> variables) : this()
473473
/// <summary>
474474
/// Evaluate the specified math or pseudo C# expression
475475
/// </summary>
476-
/// <param name="expr">the math or pseudo C# expression to evaluate</param>
476+
/// <typeparam name="T">The type in which to cast the result of the expression</typeparam>
477+
/// <param name="expression">the math or pseudo C# expression to evaluate</param>
478+
/// <returns>The result of the operation if syntax is correct casted in the specified type</returns>
479+
public T Evaluate<T>(string expression)
480+
{
481+
return (T)Evaluate(expression);
482+
}
483+
484+
/// <summary>
485+
/// Evaluate the specified math or pseudo C# expression
486+
/// </summary>
487+
/// <param name="expression">the math or pseudo C# expression to evaluate</param>
477488
/// <returns>The result of the operation if syntax is correct</returns>
478-
public object Evaluate(string expr)
489+
public object Evaluate(string expression)
479490
{
480491
bool continueEvaluation = true;
481492

482-
expr = expr.Trim();
493+
expression = expression.Trim();
483494

484495
Stack<object> stack = new Stack<object>();
485496

486-
if (GetLambdaExpression(expr, stack))
497+
if (GetLambdaExpression(expression, stack))
487498
return stack.Pop();
488499

489-
for (int i = 0; i < expr.Length && continueEvaluation; i++)
500+
for (int i = 0; i < expression.Length && continueEvaluation; i++)
490501
{
491-
string restOfExpression = expr.Substring(i, expr.Length - i);
502+
string restOfExpression = expression.Substring(i, expression.Length - i);
492503

493504
if (!(EvaluateCast(restOfExpression, stack, ref i)
494505
|| EvaluateNumber(restOfExpression, stack, ref i)
495-
|| EvaluateInstanceCreationWithNewKeyword(expr, restOfExpression, stack, ref i)
496-
|| EvaluateVarOrFunc(expr, restOfExpression, stack, ref i)
497-
|| EvaluateTwoCharsOperators(expr, stack, ref i)))
506+
|| EvaluateInstanceCreationWithNewKeyword(expression, restOfExpression, stack, ref i)
507+
|| EvaluateVarOrFunc(expression, restOfExpression, stack, ref i)
508+
|| EvaluateTwoCharsOperators(expression, stack, ref i)))
498509
{
499-
string s = expr.Substring(i, 1);
510+
string s = expression.Substring(i, 1);
500511

501-
if (EvaluateChar(expr, s, stack, ref i)
502-
|| EvaluateParenthis(expr, s, stack, ref i)
503-
|| EvaluateIndexing(expr, s, stack, ref i)
504-
|| EvaluateString(expr, s, restOfExpression, stack, ref i))
512+
if (EvaluateChar(expression, s, stack, ref i)
513+
|| EvaluateParenthis(expression, s, stack, ref i)
514+
|| EvaluateIndexing(expression, s, stack, ref i)
515+
|| EvaluateString(expression, s, restOfExpression, stack, ref i))
505516
{ }
506517
else if (operatorsDictionary.ContainsKey(s))
507518
{

CodingSeb.ExpressionEvaluator/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
3333
// en utilisant '*', comme indiqué ci-dessous :
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.1.0")]
36-
[assembly: AssemblyFileVersion("1.0.1.0")]
35+
[assembly: AssemblyVersion("1.0.2.0")]
36+
[assembly: AssemblyFileVersion("1.0.2.0")]

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ It is largely based on and inspired by the following resources [this post on st
1010
|---|---|
1111
|master|[![Build Status](https://coding-seb.visualstudio.com/_apis/public/build/definitions/cbe8d2f2-9c7a-48aa-8366-89ef39381eff/1/badge)](https://coding-seb.visualstudio.com/ExpressionEvaluator/_build/index?definitionId=1)|
1212
|dev|[![Dev Status](https://coding-seb.visualstudio.com/_apis/public/build/definitions/cbe8d2f2-9c7a-48aa-8366-89ef39381eff/2/badge)](https://coding-seb.visualstudio.com/ExpressionEvaluator/_build/index?definitionId=2)|
13-
13+
|nuget|[![NuGet Status](http://img.shields.io/nuget/v/CodingSeb.ExpressionEvaluator.svg?style=flat&max-age=86400)](https://www.nuget.org/packages/CodingSeb.ExpressionEvaluator/)|
1414

1515
## Features
1616
* Basic mathematical expression evaluation
@@ -281,7 +281,7 @@ To do so, you only need to prefix the method name with "Fluid" or "Fluent"
281281

282282
```C#
283283
// Example Add on List
284-
List("hello", "bye").FluidAdd(\"test\").Count
284+
List("hello", "bye").FluidAdd("test").Count
285285
3
286286

287287
List("hello", "bye").Select(x => x.ToUpper()).ToList().FluentAdd("test")[0]

0 commit comments

Comments
 (0)