最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#中Activator.CreateInstance()方法用法分析

 更新時(shí)間:2015年03月30日 15:43:01   作者:樂樂010  
這篇文章主要介紹了C#中Activator.CreateInstance()方法用法,實(shí)例分析了C#中Activator.CreateInstance()方法的功能、定義及使用技巧,需要的朋友可以參考下

本文實(shí)例講述了C#中Activator.CreateInstance()方法用法。分享給大家供大家參考。具體分析如下:

Activator 類

包含特定的方法,用以在本地或從遠(yuǎn)程創(chuàng)建對(duì)象類型,或獲取對(duì)現(xiàn)有遠(yuǎn)程對(duì)象的引用。

C#在類工廠中動(dòng)態(tài)創(chuàng)建類的實(shí)例,所使用的方法為:

1. Activator.CreateInstance (Type)

2. Activator.CreateInstance (Type, Object[])

兩種方法區(qū)別僅為:創(chuàng)建無參數(shù)的構(gòu)造方法和創(chuàng)建有參數(shù)的構(gòu)造函數(shù)。

//Activator.CreateInstance(Type)
object result = null;
Type typeofControl =null;
typeofControl = Type.GetType(vFullClassName);
result = Activator.CreateInstance(typeofControl);
//Activator.CreateInstance(Type,Object[])
object result = null;
Type typeofControl =null;
typeofControl = Type.GetType(vFullClassName);
result = Activator.CreateInstance(typeofControl, objParam);

但是在動(dòng)態(tài)創(chuàng)建時(shí),可能會(huì)動(dòng)態(tài)使用到外部應(yīng)用的DLL中類的實(shí)例,則此時(shí)需要進(jìn)行反編譯操作,使用Reflection命名控件下的Assembly類。

//先使用Assembly類載入DLL,再根據(jù)類的全路徑獲取類

object result = null;
Type typeofControl = null;
Assembly tempAssembly;
tempAssembly = Assembly.LoadFrom(vDllName);
typeofControl = tempAssembly.GetType(vFullClassName);
result = Activator.CreateInstance(typeofControl, objParam);

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論

子洲县| 炎陵县| 台南县| 仪陇县| 延津县| 衡南县| 汤原县| 卢湾区| 罗江县| 肇东市| 新宁县| 波密县| 伊金霍洛旗| 丰原市| 胶南市| 汝阳县| 锡林郭勒盟| 潼关县| 马龙县| 常山县| 孝义市| 凤翔县| 诸暨市| 安塞县| 射阳县| 旬邑县| 偃师市| 墨玉县| 商都县| 于都县| 都安| 顺平县| 陆川县| 邓州市| 漳州市| 新昌县| 南和县| 肇庆市| 平原县| 宜春市| 烟台市|