public static object FindInterface(System.Reflection.Assembly DLL, string InterfaceName) { // Loop through types looking for one that implements the given interface foreach (Type t in DLL.GetTypes()) { if (t.GetInterface(InterfaceName, true) != null) return DLL.CreateInstance(t.FullName); } return null; }
/// <summary> /// Creates an instance of the class. /// </summary> /// <param name="classAssembly">The assembly where the class to create is stored.</param> /// <param name="className">The fullname of the class to create.</param> /// <returns>If successful the instantiated class, otherwise null.</returns> /// <remarks></remarks> private object InstantiateMember(System.Reflection.Assembly classAssembly, string className) { object _Value = null; //Create a New Instance of the Object try { _Value = classAssembly.CreateInstance(className); } catch (System.MissingMethodException missingDefaultConstructorException) { //This error is generated by System.String. //It can also occur if the class is missing a default constructor. object dontWantToUseVarAndDontWantToSeeErrorMessageOnCompile = missingDefaultConstructorException; } catch (System.Exception unhandledException) { throw unhandledException; } //We have to verify that the value returned isn't a data type. //For example, string values require a parameter for the constructor //but work just fine without initialization. if ((_Value == null) & !(IsDataType(_Value)) & !(IsDataType(className, true))) { //The object to instantiate did not exist in the same assembly namespace. //Attempt to find the class and instantiate it. //This scenario happens with System namespace objects like System.Collections.ArrayList. _Value = System.Type.GetType(className).Assembly.CreateInstance(className); } if ((_Value == null) & !(IsDataType(_Value)) & !(IsDataType(className, true))) { //The member did not have a value and we were unable to instantiate a new class to assign to it. throw new System.MissingMethodException("Unable to deserialize Xml into " + className + ". Failed to initialize the object. Verify that the member's type supports a default constructor or that the member is automatically instantiated when the parent class is instantiated."); } return _Value; }
/// <summary> /// STATIC: Returns a new instance from Assembly, name and a list of arguments /// </summary> /// <param name="p_TypeName"></param> /// <param name="p_View"></param> /// <returns></returns> public static NodeGraphNode GenerateInstanceFromName(System.Reflection.Assembly p_Assembly, string p_TypeName, object[] p_ConstructorArgs) { object v_Out = p_Assembly.CreateInstance(p_TypeName, false, System.Reflection.BindingFlags.CreateInstance, null, p_ConstructorArgs, System.Globalization.CultureInfo.GetCultureInfo("fr-fr"), null); return v_Out as NodeGraphNode; }
private void ShowFrmProfile(Framework.Entity.Model model, System.Reflection.Assembly ass) { FrmArrayList win = new FrmArrayList(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmArrayList.CreateModuleHandle(CreateModule); win.ShowDialog(); }
private void ShowFrmProfile(Framework.Entity.Model model, System.Reflection.Assembly ass) { if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.UseWater().GetType())) { FrmUseWater win = new FrmUseWater(chapter, ass.CreateInstance(model.Class));//3.Delegate数据变量指向实例方法 win.CreateModuleIntance += new Framework.Interface.Workbench.FrmUseWater.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.UsePower().GetType())) { FrmUsePower win = new FrmUsePower(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmUsePower.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ConcreteProject().GetType())) { FrmConcreteProject win = new FrmConcreteProject(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmConcreteProject.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ConstructPrepare().GetType())) { FrmConstructPrepare win = new FrmConstructPrepare(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmConstructPrepare.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ClimateFeature().GetType())) { FrmClimateFeature win = new FrmClimateFeature(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmClimateFeature.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.RainConstruct().GetType())) { FrmRainConstruct win = new FrmRainConstruct(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmRainConstruct.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ScaffoldPowerCalculate().GetType()))//脚手架力学计算 { FrmScaffoldPowerCalculate win = new FrmScaffoldPowerCalculate(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmScaffoldPowerCalculate.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ScaffoldMaterialCalculate().GetType()))//脚手架用料计算 { FrmScaffoldMaterialCalculate win = new FrmScaffoldMaterialCalculate(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmScaffoldMaterialCalculate.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ScaffoldRecommendSelect().GetType()))//脚手架 推荐选型 { FrmScaffoldRecommendSelect win = new FrmScaffoldRecommendSelect(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmScaffoldRecommendSelect.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ScaffoldSelfSelect().GetType()))//脚手架 自行选型 { FrmScaffoldSelfSelect win = new FrmScaffoldSelfSelect(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmScaffoldSelfSelect.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ScaffoldSchematicDiagram().GetType()))//脚手架绘图 { FrmScaffoldSchematicDiagram win = new FrmScaffoldSchematicDiagram(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmScaffoldSchematicDiagram.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ScaffoldAssessment().GetType()))// 综合评价系统 { FrmAssessment win = new FrmAssessment(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmAssessment.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.Formwork().GetType()))// 板模板 { FrmFormwork win = new FrmFormwork(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmFormwork.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.BeamForm().GetType()))// 梁模板 { FrmBeamForm win = new FrmBeamForm(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmBeamForm.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ComprehensiveEvaluation().GetType()))// 综合评价 { FrmComprehensiveEvaluation win = new FrmComprehensiveEvaluation(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmComprehensiveEvaluation.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.LEC().GetType()))// LEC { FrmLEC win = new FrmLEC(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmLEC.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.FromSelect().GetType()))// 模板选择 { FrmFromSelect win = new FrmFromSelect(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmFromSelect.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.Peiban().GetType()))//配板 { Frmpeiban win = new Frmpeiban(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.Frmpeiban.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.Conretestrength1().GetType()))//混凝土强度 { FrmConretestrength1 win = new FrmConretestrength1(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmConretestrength1.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.Concretemaintain().GetType()))//混凝土制作与养护 { FrmConcretemaintain win = new FrmConcretemaintain(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmConcretemaintain.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.CompreStrength().GetType()))//混凝土抗压强度 { FrmCompreStrength win = new FrmCompreStrength(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmCompreStrength.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ConcreteMeasure().GetType()))//混凝土强度测定 { FrmConcreteMeasure win = new FrmConcreteMeasure(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmConcreteMeasure.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.FoundationPouring().GetType()))//混凝土基础浇筑 { FrmFoundationPouring win = new FrmFoundationPouring(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmFoundationPouring.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.hntzd1().GetType()))//混凝土振捣 { Frmhntzd1 win = new Frmhntzd1(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.Frmhntzd1.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.Kjjg().GetType()))//混凝土强主体浇筑 { FrmKjjg win = new FrmKjjg(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmKjjg.CreateModuleHandle(CreateModule); win.ShowDialog(); } else if (ass.CreateInstance(model.Class).GetType().Equals(new Framework.Model.ConcreteConstructionMachinery().GetType()))//混凝土施工机械选择 { FrmConcreteConstructionMachinery win = new FrmConcreteConstructionMachinery(chapter, ass.CreateInstance(model.Class)); win.CreateModuleIntance += new Framework.Interface.Workbench.FrmConcreteConstructionMachinery.CreateModuleHandle(CreateModule); win.ShowDialog(); } }