void PluginCommandScriptDecorator_ScriptExecuted(object sender, ScriptScopeEventArgs e) { //get name of subclass python-type from PluginCommandBase var pluginTypes = (from item in e.Scope.GetItems() let @type = item.Value as PythonType where @type != null let clrType = (Type)@type where clrType.IsAbstract == false where clrType.IsInterface == false let @interfaces = clrType.GetInterfaces() where @interfaces.Contains(typeof(IScriptCommand)) select item.Key); ObjectOperations op = e.Scope.Engine.Operations; foreach (var pluginType in pluginTypes) { object @class = e.Scope.GetVariable(pluginType); // get the class object object @instance = op.Call(@class); // create the instance //object method = op.GetMember(instance, "Execute"); // get a method //op.Call(method); // call method and get the result var cmd = @instance as IScriptCommand; commandRepository.AddCommand(cmd); OnCommandCreated (cmd); } }
void PluginCommandScriptDecorator_RegisterGlobals(object sender, ScriptScopeEventArgs e) { e.Scope.SetVariable("Commands", container.Resolve<ICommandRepository>()); e.Scope.SetVariable("IoC", container); }