六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

.net的reflection (2)

[摘要]一旦得到類(lèi)對(duì)象,上表中所列的方法就能被叫來(lái)調(diào)用reflaction.第一個(gè)例子將檢查在CSharpReflectionSamples.Reflect類(lèi)中的得到方法的信息。第一塊代碼用來(lái)定義類(lèi)中的每個(gè)...
一旦得到類(lèi)對(duì)象,上表中所列的方法就能被叫來(lái)調(diào)用reflaction.第一個(gè)例子將檢查在CSharpReflectionSamples.Reflect類(lèi)中的得到方法的信息。第一塊代碼用來(lái)定義類(lèi)中的每個(gè)方法的名字,第二塊代碼將闡述得到方法信息。向下面所展示的,我們將用一個(gè)數(shù)組來(lái)保存用GetMethod()方法返回的方法信息。MethodInfo類(lèi)包含信息為方法的名字,不管是否是虛擬的,它都是可見(jiàn)的,等等。

namespace CSharpReflectionSamples
{
using System;
using System.Reflection;

/// <summary>
/// Summary description for Client.
/// </summary>
public class Client
{
public static void Main()
{
// the typeof operator and the GetType method
// both return a 'Type' object.
Type type1 = typeof(Reflect);
Reflect objTest = new Reflect(0);
Type type2 = objTest.GetType();

Console.WriteLine("Type of objTest is {0}", type2);
Console.WriteLine();
// pause
Console.ReadLine();

// reflect method information
MethodInfo[] minfo = type1.GetMethods();
// iterate through methods
foreach (MethodInfo m in minfo)
{
Console.WriteLine(m);
}
Console.WriteLine();
}
}
}

下一個(gè)例子將展示動(dòng)態(tài)得到對(duì)象有可能接觸的每個(gè)構(gòu)造器的信息。類(lèi)似與上面的例子,我們將返回一個(gè)包含每個(gè)構(gòu)造器的信息ConstructorInfo對(duì)象。

namespace CSharpReflectionSamples
{
using System;
using System.Reflection;

/// <summary>
/// Summary description for Client.
/// </summary>
public class Client
{
public static void Main()
{
// the typeof operator and the GetType method
// both return a 'Type' object.
Type type1 = typeof(Reflect);
Reflect objTest = new Reflect(0);
Type type2 = objTest.GetType();

Console.WriteLine("Type of objTest is {0}", type2);
Console.WriteLine();
// pause
Console.ReadLine();

// reflect constructors
ConstructorInfo[] cinfo = type1.GetConstructors();
// iterate through constructors
foreach (ConstructorInfo c in cinfo)
{
Console.WriteLine(c);
}
}
}
}

最后一部分,也許是reflection名字空間中最激動(dòng)人心的部分,是在運(yùn)行時(shí)動(dòng)態(tài)調(diào)用類(lèi)方法。有兩種方法,首先,我們將建立一個(gè)數(shù)組來(lái)存儲(chǔ)參數(shù),這些參數(shù)被構(gòu)造器用來(lái)建造對(duì)象。第二,一個(gè)System.Object對(duì)象將對(duì)抗CreateInstance方法的對(duì)象。以得到想得到對(duì)象的例子。最后,當(dāng)我們有了對(duì)象的資料,我們能夠調(diào)用任何使用MethodParm數(shù)組的方法。下面是代碼:

namespace CSharpReflectionSamples
{
using System;
using System.Reflection;

/// <summary>
/// Summary description for Client.
/// </summary>
public class Client
{
public static void Main()
{
// the typeof operator and the GetType method
// both return a 'Type' object.
Type type1 = typeof(Reflect);
Reflect objTest = new Reflect(0);
Type type2 = objTest.GetType();



// dynamic creation and invocation
// instantiate the Reflect object, passing
// a value of 1 to the constructor
object[] oConstructParms = new object[] {1};
object obj = Activator.CreateInstance(type1, oConstructParms);
// invoke method of reflect object
object[] oMethodParms = new object[] {17};
int intResult = (int)type1.InvokeMember("AMethod", BindingFlags.Default
BindingFlags.InvokeMethod, null, obj, oMethodParms);
Console.WriteLine("Result of calling AMethod on {0} is {1}",
type1.Name, intResult);
// pause
Console.ReadLine();
}
}
}


這篇文章闡述了.net Reflaction的基礎(chǔ),在下一部分,我將和大家討論進(jìn)一步的話題,比如,動(dòng)態(tài)發(fā)布中間語(yǔ)言,旗幟綁定,和中間語(yǔ)言原則。





標(biāo)簽:.net的reflection (2) 
主站蜘蛛池模板: 亚洲女人的天堂 | 亚洲视频男人的天堂 | 四虎永久在线免费观看 | 午夜1000集 | 青青草好吊色 | 日韩成人免费在线 | 青娱乐在线视频免费观看 | 天天躁夜夜躁狂狂躁综合 | 欧美一区二区三区精品 | 天堂网2017| 欧美一级在线观看视频 | 色丁香在线 | 一区在线看 | 日韩视频中文字幕专区 | 亚洲综合色一区 | 日韩精品在线视频观看 | 无码精品日韩中文字幕 | 人人揉揉香蕉大免费不卡 | 日韩精品亚洲人成在线播放 | 最近中文字幕资源 | 视频一区二区三区在线观看 | 污污免费在线观看 | 午夜色影院 | 欧洲精品视频完整版在线 | 婷婷开心激情网 | 婷婷伊人五月 | 视频一区二区不卡 | 一二三四在线观看高清在线观看一 | 一区在线看| 亚洲第一页综合 | 色综合天天综合给合国产 | 亚洲成av人片天堂网 | 日本国产在线视频 | 深夜视频在线观看免费 | 亚欧洲精品在线视频免费观看 | 伊人操| 亚洲综合久 | 色天使色| 色久天 | 日本一道高清 | 特色毛片 |