zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
449 stars 86 forks source link

How can i call External dll method? #21

Closed pimier15 closed 6 years ago

pimier15 commented 6 years ago

I want to use my dll method with eval. How can i do this?

Test code is this.

// Test
public class Program
{
    static void Main( string [ ] args )
    {
        string path = @"E:\Temp\test.png";
        Image<Bgr,byte> res = Eval.Execute<Image<Bgr,byte>>(
            @"
                WriteLine( Path );
                return F(Path);
            " , new { Path = path , F = Getimg }
            );

        WriteLine();
    }

    static Func<string,string> Getimg = Path => "Image";
}
JonathanMagnan commented 6 years ago

Hello @pimier15 ,

Depending on what you exactly need, here is three different way to register type & assembly.

// Register a specific type
EvalManager.DefaultContext.RegisterType(typeof(Program));

// Register a specific assembly
EvalManager.DefaultContext.RegisterAssembly(typeof(Program).Assembly);

// Register all domain assemblies
EvalManager.DefaultContext.RegisterDomainAssemblies();

Let me know if this answer helped you to solve your problem.

Best Regards,

Jonathan

JonathanMagnan commented 6 years ago

Hello @pimier15 ,

We are currently making some issue cleanup.

Feel free to reopen if you believe we closed it by mistake

Best Regards,

Jonathan