-
-
Notifications
You must be signed in to change notification settings - Fork 581
Closed
Description
Saw a question on Stack Overflow while researching and couldn't get it to work with the extension methods provided by C# itself.
// Works
public class Foo
{
public string Name { get; } = "Bar";
}
public static class CustomStringExtensions
{
public static bool StartsWith(this string value, string value2) => value.StartsWith(value2);
}
Engine engine = new Engine(options =>
{
options.AddExtensionMethods(typeof(CustomStringExtensions));
});
bool result = engine
.SetValue("foo", new Foo())
.Evaluate("foo.Name.StartsWith('B')")
.AsBoolean();
// Doesn't work
public class Foo
{
public string Name { get; } = "Bar";
}
Engine engine = new Engine(options =>
{
// Also tried these
//options.AllowClr();
//options.AllowOperatorOverloading();
//options.AddExtensionMethods(typeof(String));
options.AddExtensionMethods(typeof(string));
});
bool result = engine
.SetValue("foo", new Foo())
.Evaluate("foo.Name.StartsWith('B')")
.AsBoolean();
bool result = engine
.SetValue("foo", new Foo())
.Evaluate("foo.Name.StartsWith('B')")
.AsBoolean();
Is it because some overloading? I'm curious about the reason.
I see there isn't really anything documented about how the extension method support is to be used. Could an example be added, and maybe also that native extensions methods do not work, or if they do, how they can be added. Thanks!
When will version 3 become available, as I see it's already beta since Oct 2016? :)
Metadata
Metadata
Assignees
Labels
No labels