• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

        當(dāng)前位置:雨林木風(fēng)下載站 > 技術(shù)開發(fā)教程 > 詳細(xì)頁面

        .net的reflection (2)

        .net的reflection (2)

        更新時(shí)間:2022-05-14 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

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

        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)造器的信息。類似與上面的例子,我們將返回一個(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)用類方法。有兩種方法,首先,我們將建立一個(gè)數(shù)組來存儲(chǔ)參數(shù),這些參數(shù)被構(gòu)造器用來建造對(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ā)布中間語言,旗幟綁定,和中間語言原則。


        溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

        本類教程下載

        系統(tǒng)下載排行

        主站蜘蛛池模板: 日本激情猛烈在线看免费观看| 亚洲酒色1314狠狠做| 亚洲第一se情网站| 国产成人无码免费视频97 | 日韩免费毛片视频| 亚洲av永久无码天堂网| 国产美女精品久久久久久久免费| 日本亚洲免费无线码 | 亚洲国产精品久久久久秋霞小| 永久免费无码网站在线观看| 自拍偷自拍亚洲精品播放| 亚洲国产精品无码久久久久久曰| 国产精品成人啪精品视频免费| 亚洲乱码精品久久久久..| 99爱在线观看免费完整版| 亚洲一级大黄大色毛片| 永久免费毛片手机版在线看| 国产精品免费久久| 老色鬼久久亚洲AV综合| 好吊妞在线新免费视频| 全部在线播放免费毛片| 久久综合日韩亚洲精品色| 久久久久久久免费视频| 大桥未久亚洲无av码在线| 中文字幕久久亚洲一区| 7x7x7x免费在线观看| 亚洲私人无码综合久久网| 亚洲国产综合精品一区在线播放| 免费福利在线视频| 亚洲人成网站色7799| 亚洲中文无韩国r级电影| 最近最好最新2019中文字幕免费| 亚洲人成综合网站7777香蕉 | 亚洲大尺度无码专区尤物| 动漫黄网站免费永久在线观看| 免费播放美女一级毛片| 亚洲国产综合精品中文第一区 | 成人精品视频99在线观看免费| 亚洲日产2021三区在线| 国产免费观看a大片的网站| 无码国产精品一区二区免费16|