反射的使用

2022-03-29 13:06:13 字數 2242 閱讀 8974

1.將主程式介面上的icon賦給基類內的icon(同時其他子類也具有了此icon):

public partial class baseform : form}}

}}

2、獲取介面:

assembly assembly = assembly.loadfrom(system.io.path.getdirectoryname(system.reflection.assembly.getexecutingassembly().location) + "\\a.b.ui.dll");

this.iuic = assembly.createinstance("a.b.ui.uic", false, bindingflags.default, null, null, null, null) as iuic;

3、獲取xml檔案

assembly assembly = assembly.loadfrom(system.io.path.getdirectoryname(system.reflection.assembly.getexecutingassembly().location) + "\\a.b.ui.dll");

stream stream = assembly.getmanifestresourcestream(assembly.getname().name + ".config.xml");

system.xml.xmldocument xmldoc = new system.xml.xmldocument();

xmldoc.load(stream);

stream.close();

stream.dispose();

4、建立窗體:

public static form createform(string formassemblyfile, string formfullname, object formargs, string formname, string formtext)

else

if (form == null)

\nformfullname=\nformname=\nformtext=",

formassemblyfile,

formfullname,

formname,

formtext);

throw new exception(strerror);

}if (!string.isnullorempty(formname))

if (!string.isnullorempty(formtext))

return form;

}

4、獲取版本資訊:

(1)assembly.getexecutingassembly().getname().version.tostring();

(2)object attributes = assembly.getexecutingassembly().getcustomattributes(typeof(assemblydescriptionattribute), false);

if (attributes.length == 0)

return ((assemblydescriptionattribute)attributes[0]).description;

(3)object attributes = assembly.getexecutingassembly().getcustomattributes(typeof(assemblyproductattribute), false);

if (attributes.length == 0)

return ((assemblyproductattribute)attributes[0]).product;

反射對控制項的操作:呼叫函式(含引數|不含引數)

#region 呼叫控制項方法

private void invokemethod(string methodname, control control, object args)

else

if (mi != null)

}catch (exception e)

}#endregion

#region 設定控制項屬性

private void setpropertyvalue(string propertyname, control control, object propertyvalue)

}#endregion

反射的使用

當我們一開始使用反射的時候,首先理解的是,他可以攔截乙個方法,並執行其方法。com.ml.maskpro.ui.mainactivity中包含如下方法 public string getname string name private string getage int age 然後我們攔截這兩個方...

反射的使用

1.首先我們得知道什麼是反射?反射其實就是通過class檔案物件去獲取該檔案中的成員變數,構造方法,成員方法。2.獲取class檔案物件的方式有三種 第一種是通過object類中的getclass 方法來獲取 student s new student class c1 s.getclass 第二種...

c 反射的使用

獲取具有指定名稱的type,執行區分大小寫的搜尋。tips gettype包括object.gettype 和type.gettype6個過載靜態方法 type ty type.gettype exthomeexpansion.view.zyl 通過引導程式集也可以獲得對應類的型別 其中load方法...