GameDevWare.Dynamic.Expressions
2.2.0
See the version list below for details.
dotnet add package GameDevWare.Dynamic.Expressions --version 2.2.0
NuGet\Install-Package GameDevWare.Dynamic.Expressions -Version 2.2.0
<PackageReference Include="GameDevWare.Dynamic.Expressions" Version="2.2.0" />
paket add GameDevWare.Dynamic.Expressions --version 2.2.0
#r "nuget: GameDevWare.Dynamic.Expressions, 2.2.0"
// Install GameDevWare.Dynamic.Expressions as a Cake Addin #addin nuget:?package=GameDevWare.Dynamic.Expressions&version=2.2.0 // Install GameDevWare.Dynamic.Expressions as a Cake Tool #tool nuget:?package=GameDevWare.Dynamic.Expressions&version=2.2.0
Introduction
Attention! This is a paid package, you can not use it in your project if you have not purchased it through Unity Asset Store.
This package provides the API for parsing and expression execution written in C#. It is specially designed to work with the Unity on various platforms. Since it is written in C# 3.5, it should work with any version of Unity.
It is tested to work on:
- IOS
- Android
- WebGL
- PC/Mac
It should work on any other platforms.
API
- CSharpExpression
- Evaluate
- Parse
- AotCompilation
- RegisterFunc
- RegisterForFastCall
Example
Parsing C# expression into System.Linq.Expression.Expression[T]:
var mathExpr = "Math.Max(x, y)";
var exprTree = CSharpExpression.Parse<double, double, double>(mathExpr, arg1Name: "x", arg2Name: "y")
// exprTree -> Expression<Func<double, double, double>>
Evaluating C# expression:
var arifExpr = "2 * (2 + 3) << 1 + 1 & 7 | 25 ^ 10";
var result = CSharpExpression.Evaluate<int>(arifExpr);
// result -> 19
Parser
The parser recognizes the C# 4 grammar only. It includes:
- Arithmetic operations
- Bitwise operations
- Logical operations
- Conditional operator
- Null-coalescing operator
- Method/Delegate/Constructor call
- Property/Field access
- Indexers
- Casting and Conversion
- Is Operator
- As Operator
- TypeOf Operator
- Default Operator
- Expression grouping with parentheses
- Checked/Unchecked scopes
- Aliases for Built-In Types
- Null-conditional Operators
- Power operator
**
- Lambda expressions
- "true", "false", "null"
Nullable types are supported. Generics are supported. Enumerations are supported. Type inference is not available and your should always specify generic parameters on types and methods.
Known Types
For security reasons the parser does not provide access to any types except:
- argument types
- primitive types
- Math, Array, Func<> (up to 4 arguments) types
To access other types your should pass typeResolver parameter in Parse and Evaluate method:
var typeResolver = new KnownTypeResolver(typeof(Mathf), typeof(Time));
CSharpExpression.Evaluate<int>("Mathf.Clamp(Time.time, 1.0f, 3.0f)", typeResolver);
If you want to access all types in UnityEngine you can pass AssemblyTypeResolver.UnityEngine as typeResolver parameter.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net35 is compatible. net40 was computed. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 2.0
- No dependencies.
-
.NETFramework 3.5
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
# 2.2.0
Features
* added support for void expressions (Action<> delegates)
* added support of '.NET Standart 1.3' and '.NET Core 2.0' platforms
# 2.1.4
Features
* added more descriptive message to member binding error
* added autodoc comments for public members
* hidden ReadOnlyDictionary from public access
* removed WEBGL check for later version of Unity, because unsigned types bug was fixed
* added generic types and generic methods
* added nullable types via '?' suffix
* added lambda expression syntax '() => x' and 'new Func(a => x)'
* added support for expression parameter re-mapping with lambda syntax at beggining of expression
* added support for Func<> lambdas on AOT environments
* added additional constructor to Binder class
* added ArgumentsTree ToString method
* added build-in types aliases support during static members binding
Bug Fixes
* fixed error with wrongly resolved types (only by name) in KnownTypeResolver
* fixed bug with ACCESS_VIOLATION on iOS (Unity 5.x.x IL2CPP)
* fixed few Unity 3.4 related errors in code
* fixed 'new' expression parsed with error on chained calls new a().b().c()
* fixed some cases of lifted binary/unary/conversion operations
* fixed some AOT'ed operations on System.Boolean type
* fixed null-propagation chains generate invalid code
* fixed some edge cases of resolving nested generic types
* fixed error with types without type.FullName value
* fixed Condition operator types promotion
* fixed Power operator types promotion and null-lifting
* fixed enum constants threated as underlying types during binary/unary operations
Breaking changes
* ParserNode renamed to ParseTreeNode
* ExpressionTree renamed to SyntaxTreeNode
* ExpressionBuilder renamed to Binder
* ITypeResolutionService renamed to ITypeResolver
* ITypeResolver.GetType removed
* ITypeResolver now could be configured with TypeDiscoveryOptions