3

i want to make plugin support for my program

the goal is to make it compile files in plugin folder and launch few methods but i can get it working

my current progress using CSScriptLibrary :

public static void run(String fileName, String methodName, params Object[] parameters)
    {
        FileInfo f = new FileInfo(fileName);

        try
        {
            CSScript.Evaluator.Reset();
            CSScript.Evaluator.ReferenceAssembliesFromCode(File.ReadAllText(Environment.CurrentDirectory + @"\addons\ResourceManager.cs"));
            dynamic block = CSScript.Evaluator.LoadCode(File.ReadAllText(f.FullName));
            block.Load(parameters); // <---- Exception
        }
        catch(Exception e)
        {
            Console.WriteLine(e.ToString());
        }
    }

but it throws exception :

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'WAddon.Load(Weird.ResourceManager)' has some invalid arguments AddonManager.cs:line 28

the addon file :

using System;
using Weird;

class WAddon
{
public static void Load(ResourceManager resManager)
{
    resManager.add("var", "0");
}
}

i dont think resmanager class is important anyways want to pass instance of it to load function so it can change things on original program

4

1 回答 1

2

did it

using System;  
using Weird;  

public class WAddon : IAddon  
{  
    public void Load(ResourceManager resManager)  
    {  
        resManager.add("var", "24");  
    }  
}

needed to add interface :

using System;    

namespace Weird  
{  
    public interface IAddon  
    {  
        void Load(ResourceManager resManager, Overlay overlay);  
    }  
}

code from run method :

CSScript.Evaluator.ReferenceAssembliesFromCode(
        Weird.Properties.Resources.iaddon_source
    );
IAddon block = (IAddon) CSScript.Evaluator.LoadCode(File.ReadAllText(f.FullName));

block.Load(resManager, overlay);  
于 2015-05-14T12:35:51.877 回答