/// <summary> /// 创建函数委托 /// </summary> /// <param name="delegateType">委托类型</param> /// <returns></returns> public Delegate GetRuntimeMethodDelegate(Type delegateType) { string body = Static().Body(GetScript()).Builder(); Assembly assembly = null; if (!_useFileComplie) { assembly = ScriptComplier.StreamComplier(body, _class_name, SingleError); } else { assembly = ScriptComplier.FileComplier(body, _class_name, SingleError); } if (assembly == null) { return(null); } return(AssemblyOperator .Loader(assembly)[_class_name] .GetMethod(_method_name) .CreateDelegate(delegateType)); }
/// <summary> /// 根据命名空间和类的位置获取类型 /// </summary> /// <param name="content">脚本内容</param> /// <param name="classIndex">命名空间里的第index个类</param> /// <param name="namespaceIndex">第x个命名空间</param> /// <returns></returns> public static Type GetType(string content, int classIndex = 1, int namespaceIndex = 1) { classIndex -= 1; namespaceIndex -= 1; Assembly assembly = null; string className = ScriptComplier.GetClassName(content, classIndex, namespaceIndex); assembly = ScriptComplier.FileComplier(content, className); return(AssemblyOperator.Loader(assembly)[className]); }
/// <summary> /// 根据命名空间和类的位置获取类型 /// </summary> /// <param name="content">脚本内容</param> /// <param name="classIndex">命名空间里的第index个类</param> /// <param name="namespaceIndex">第namespaceIndex个命名空间</param> /// <returns></returns> public static Type GetClassType(string content, int classIndex = 1, int namespaceIndex = 1) { //获取程序集 Assembly assembly = ScriptComplierEngine.FileComplier(content, out _); //根据索引获取类名 string className = ScriptHelper.GetClassName(content, classIndex, namespaceIndex); //获取类型 return(AssemblyOperator.Loader(assembly)[className]); }
/// <summary> /// 根据命名空间和类的位置获取类型 /// </summary> /// <param name="content">脚本内容</param> /// <param name="classIndex">命名空间里的第index个类</param> /// <param name="namespaceIndex">第namespaceIndex个命名空间</param> /// <returns></returns> public Type GetType(string content, int classIndex = 1, int namespaceIndex = 1) { //根据索引获取类名 string className = ScriptComplieEngine.GetTreeAndClassName(content, classIndex, namespaceIndex).ClassName; //获取程序集 Assembly assembly = GetAssemblyByScript(content); //获取类型 return(AssemblyOperator.Loader(assembly)[className]); }
public static Type GetStructType(string content, int classIndex = 1, int namespaceIndex = 1) { //根据索引获取类名 string structName = GetStructName(content, classIndex, namespaceIndex); //获取程序集 Assembly assembly = ScriptComplieEngine.FileComplier(content); //获取类型 return(AssemblyOperator.Loader(assembly)[structName]); }
/// <summary> /// 创建函数委托 /// </summary> /// <param name="delegateType">委托类型</param> /// <returns></returns> public static Delegate GetRuntimeMethodDelegate(string content, Type delegateType) { string className = _get_class.Match(content).Groups["result"].Value; Assembly assembly = ScriptComplier.StreamComplier(content, className, SingleError); if (assembly == null) { return(null); } return(AssemblyOperator .Loader(assembly)[className] .GetMethod("DynamicMethod") .CreateDelegate(delegateType)); }
/// <summary> /// 创建函数委托 /// </summary> /// <param name="delegateType">委托类型</param> /// <returns></returns> public Delegate GetRuntimeMethodDelegate(Type delegateType) { string body = MakerHeader().MakerContent(GetMethodString()).Script; Assembly assembly = ScriptComplier.StreamComplier(body, _class_name, SingleError); if (assembly == null) { return(null); } return(AssemblyOperator .Loader(assembly)[_class_name] .GetMethod("DynimacMethod") .CreateDelegate(delegateType)); }
/// <summary> /// 获取编译后的类型 /// </summary> /// <param name="content">脚本内容</param> /// <param name="typeName">类型名称</param> /// <returns></returns> public Type GetTypeByScript(string content, string typeName) { Assembly assembly = GetAssemblyByScript(content); if (assembly == null) { return(null); } var type = AssemblyOperator.Loader(assembly)[typeName]; if (type == null) { Exception.ErrorFlag = ComplieError.Type; Exception.Message = $"发生错误,无法从程序集{assembly.FullName}中获取类型{typeName}!"; } return(type); }
/// <summary> /// 编译脚本,生成委托 /// </summary> /// <param name="className">类名</param> /// <param name="methodName">方法名</param> /// <param name="delegateType">委托类型</param> /// <returns></returns> public static Delegate GetDelegate <T>(string className, string content, string methodName) { //获取程序集 Assembly assembly = ScriptComplierEngine.StreamComplier(content, out _); //判空 if (assembly == null) { return(null); } //获取方法委托 return(AssemblyOperator .Loader(assembly)[className] .GetMethod(methodName) .CreateDelegate(typeof(T))); }
/// <summary> /// 编译并返回委托 /// </summary> /// <returns></returns> public Delegate Complie() { //获取程序集 Assembly assembly = GetAssemblyByScript( ClassTemplate .Using(MethodTemplate.UsingRecoder.Types) .ClassBody(MethodTemplate.Builder()._script) .Builder().Script ); //判空 if (assembly == null) { return(null); } //获取方法委托 return(AssemblyOperator .Loader(assembly)[ClassTemplate.ClassNameScript] .GetMethod(MethodTemplate.MethodNameScript) .CreateDelegate(MethodTemplate.DelegateType)); }
/// <summary> /// 根据类名获取类,前提类必须是成功编译过的 /// </summary> /// <param name="name"></param> /// <returns></returns> public static Type GetType(string name) { return(AssemblyOperator.Loader(ScriptComplieEngine.ClassMapping[name])[name]); }