public T CreateScriptDelegate <T>(String scriptName, XmlNode ctx = null) where T : class { if (scriptName == null) { return(null); } if (ScriptObject == null) { throw new BMNodeException(ctx, "Cannot create script [{0}]: No script specified at the pipeline.", scriptName); } Type t = ScriptObject.GetType(); MethodInfo mi = t.GetMethod(scriptName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance); if (mi == null) { throw new BMNodeException(ctx, "Cannot find method {0} in class {1}.", scriptName, t.FullName); } T dlg; try { dlg = (T)(Object)Delegate.CreateDelegate(typeof(T), ScriptObject, mi); } catch { ParameterInfo[] parms = mi.GetParameters(); if (parms.Length != 3 || parms[0].ParameterType != typeof(PipelineContext) || parms[1].ParameterType != typeof(String) || parms[2].ParameterType != typeof(Object)) { throw; } PipelineAction.OldScriptDelegate old = (PipelineAction.OldScriptDelegate)(Object) Delegate.CreateDelegate(typeof(PipelineAction.OldScriptDelegate), ScriptObject, mi); ImportEngine.ImportLog.Log(_LogType.ltWarning, "Script [{0}] still has a key-param. It will be wrapped for backward compatibility.", scriptName); dlg = (T)(Object) new ScriptOldWrapper(old).CreateDelegate(); } logger.Log("-- CreateScriptDelegate({0}) -> {1}.", scriptName, dlg); return((T)dlg); }
public ScriptOldWrapper(PipelineAction.OldScriptDelegate fn) { oldDelegate = fn; }