TagBites.Expressions
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package TagBites.Expressions --version 1.0.1
NuGet\Install-Package TagBites.Expressions -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TagBites.Expressions" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TagBites.Expressions --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TagBites.Expressions, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TagBites.Expressions as a Cake Addin #addin nuget:?package=TagBites.Expressions&version=1.0.1 // Install TagBites.Expressions as a Cake Tool #tool nuget:?package=TagBites.Expressions&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TagBites.Expressions
Converts C# text expressions into LINQ expressions using Roslyn, supporting complete language syntax.
Example
public void BasicUseTest()
{
var expression = "new [] { 1, 2, 3 }.Select(x => (x, x + 1).Item2).Sum()";
var func = ExpressionParser.Parse(expression, null).Compile();
Assert.Equal(9, func.DynamicInvoke());
}
public void SimpleTest()
{
var func = Parse("(a + b) / (double)b");
Assert.Equal(2.5d, func(3, 2));
func = Parse("a switch { 1 => b, 2 => b * 2, _ => b + a }");
Assert.Equal(2, func(1, 2));
Assert.Equal(4, func(2, 2));
Assert.Equal(5, func(3, 2));
static Func<int, int, double> Parse(string expression)
{
var options = new ExpressionParserOptions
{
Parameters =
{
(typeof(int), "a"),
(typeof(int), "b")
},
ResultCastType = typeof(double)
};
var lambda = ExpressionParser.Parse(expression, options);
return (Func<int, int, double>)lambda.Compile();
}
}
public void TypeTest()
{
var m = new TestModel { X = 1, Y = 2 };
var func = Parse("X + Y");
Assert.Equal(3, func(m));
func = Parse("X + Nested.X");
Assert.Equal(3, func(m));
func = Parse("X + new TestModel { X = 1, Y = 2 }.Y");
Assert.Equal(3, func(m));
func = Parse("X + (X == 1 ? Nested.X : Nested.Y)");
Assert.Equal(3, func(m));
Assert.Equal(7, func(new TestModel { X = 2, Y = 3 }));
static Func<TestModel, int> Parse(string expression)
{
var options = new ExpressionParserOptions
{
Parameters =
{
(typeof(TestModel), "this")
},
UseFirstParameterAsThis = true,
ResultType = typeof(int)
};
var lambda = ExpressionParser.Parse(expression, options);
return (Func<TestModel, int>)lambda.Compile();
}
}
private class TestModel
{
private TestModel? _nested;
public int X { get; set; }
public int Y { get; set; }
public TestModel Nested => _nested ??= new TestModel { X = Y, Y = X + Y };
}
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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | 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 | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.