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

5
  • msdn.microsoft.com/en-us/library/ms972962.aspx Commented May 13, 2015 at 19:54
  • I swear there was a built in set of classes they introduced a while back but I can't think of it right now Commented May 13, 2015 at 20:41
  • @RadioSpace Did you mean MEF? msdn.microsoft.com/de-de/library/ee332203.aspx Commented May 13, 2015 at 22:29
  • @Koopakiller that's the one. English version. thanks I forgot the name. Commented May 14, 2015 at 0:03
  • @RadioSpace Thank you, I forgot to change the language of the link. Commented May 14, 2015 at 13:30

1 Answer 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);  
Sign up to request clarification or add additional context in comments.

1 Comment

@Karl-Johan somewhy the formatting didnt work well thanks anyways

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.