Reputation: 59
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
Upvotes: 3
Views: 353
Reputation: 59
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);
Upvotes: 2