Skip to content

Instantly share code, notes, and snippets.

@davidwhitney
Last active August 29, 2015 13:59
Show Gist options
  • Save davidwhitney/10744710 to your computer and use it in GitHub Desktop.
Save davidwhitney/10744710 to your computer and use it in GitHub Desktop.
LOLWUT Dynamic expressions!
public class SomeType
{
public string Name { get; set; }
}
const string body = "(MyThing.Name == \"Awesome\")";
var p = Expression.Parameter(typeof (SomeType), "MyThing");
var e = DynamicExpression.ParseLambda(new[] {p}, null, body);
var typeHere = new SomeType { Name = "Awesome" };
var output = e.Compile().DynamicInvoke(typeHere);
Assert.That(output, Is.True);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment