Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended Methods #44

Closed
TheoVC opened this issue Jan 21, 2020 · 2 comments
Closed

Extended Methods #44

TheoVC opened this issue Jan 21, 2020 · 2 comments

Comments

@TheoVC
Copy link

TheoVC commented Jan 21, 2020

this a complete library... one of the best I've seen. the only feature that is missing is support for extended methods.

for example. I declare this class

public static class MyAuxiliarMethods
{
    public static string MyExtendedMethod(this string str)
    {
        return str + " extended";
    }
}

then I should add this type somewhere so all the exteded methods became registered.
or maybe just adding the corresponding namespace...

then I could evaluate an expression like this:

AnStringVariable.MyExtendedMethod()

@codingseb
Copy link
Owner

codingseb commented Jan 22, 2020

Hello @TheoVC, thanks for your issues.
For this one a solution already exists but I didn't documented this yet:

    public static class StringExtendedMethods
    {
        public static string AddExtended(this string str)
        {
            return str + " extended";
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ExpressionEvaluator evaluator = new ExpressionEvaluator(new Dictionary<string, object>()
            {
                { "x", "Test" }
            });

            evaluator.StaticTypesForExtensionsMethods.Add(typeof(StringExtendedMethods));

            Console.WriteLine(evaluator.Evaluate("x.AddExtended()"));
        }
    }

I will update the documentation as soon as possible

@codingseb
Copy link
Owner

I added some documentation about Extension method on the wiki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants