久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

反射(轉(zhuǎn))

 牛人的尾巴 2015-10-28

反射(轉(zhuǎn)) - 2

(2010-05-05 15:46:32)
標(biāo)簽:

雜談

分類: C#
窺一斑而知全豹,一個(gè)對(duì)象實(shí)例泄漏的密秘(這個(gè)比較爽)
通過(guò)一個(gè)對(duì)象實(shí)例,我們可以獲得包含這個(gè)對(duì)象實(shí)例的類的Assembly,進(jìn)而獲得整個(gè)Assembly的信息.

 1反射(轉(zhuǎn)) <wbr>- <wbr>2using System;
 2反射(轉(zhuǎn)) <wbr>- <wbr>2using System.Reflection;
 3反射(轉(zhuǎn)) <wbr>- <wbr>2namespace TestReflection
 4反射(轉(zhuǎn)) <wbr>- <wbr>2{
 5反射(轉(zhuǎn)) <wbr>- <wbr>2    class Program
 6反射(轉(zhuǎn)) <wbr>- <wbr>2    {
 7反射(轉(zhuǎn)) <wbr>- <wbr>2        public static void Main(string[] args)
 8反射(轉(zhuǎn)) <wbr>- <wbr>2        {
 9反射(轉(zhuǎn)) <wbr>- <wbr>2            object new AX();
10反射(轉(zhuǎn)) <wbr>- <wbr>2            //獲取對(duì)象所屬的Assembly的所有類的基本信息
11反射(轉(zhuǎn)) <wbr>- <wbr>2            new TestObjectType().TestObjectTypeNow(A);
12反射(轉(zhuǎn)) <wbr>- <wbr>2        }
13反射(轉(zhuǎn)) <wbr>- <wbr>2    }
14反射(轉(zhuǎn)) <wbr>- <wbr>2
15反射(轉(zhuǎn)) <wbr>- <wbr>2    class AX
16反射(轉(zhuǎn)) <wbr>- <wbr>2    {
17反射(轉(zhuǎn)) <wbr>- <wbr>2        internal int kkkkkkkk 0;
18反射(轉(zhuǎn)) <wbr>- <wbr>2        public int ooooooooo;
19反射(轉(zhuǎn)) <wbr>- <wbr>2        private int property;
20反射(轉(zhuǎn)) <wbr>- <wbr>2
21反射(轉(zhuǎn)) <wbr>- <wbr>2        public int Property
22反射(轉(zhuǎn)) <wbr>- <wbr>2        {
23反射(轉(zhuǎn)) <wbr>- <wbr>2            get return property; }
24反射(轉(zhuǎn)) <wbr>- <wbr>2            set property value; }
25反射(轉(zhuǎn)) <wbr>- <wbr>2        }
26反射(轉(zhuǎn)) <wbr>- <wbr>2        public void A()
27反射(轉(zhuǎn)) <wbr>- <wbr>2        {
28反射(轉(zhuǎn)) <wbr>- <wbr>2            Console.WriteLine("AX's function!~");
29反射(轉(zhuǎn)) <wbr>- <wbr>2        }
30反射(轉(zhuǎn)) <wbr>- <wbr>2    }
31反射(轉(zhuǎn)) <wbr>- <wbr>2
32反射(轉(zhuǎn)) <wbr>- <wbr>2    class AXzhz
33反射(轉(zhuǎn)) <wbr>- <wbr>2    {
34反射(轉(zhuǎn)) <wbr>- <wbr>2    }
35反射(轉(zhuǎn)) <wbr>- <wbr>2
36反射(轉(zhuǎn)) <wbr>- <wbr>2    class TestObjectType
37反射(轉(zhuǎn)) <wbr>- <wbr>2    {
38反射(轉(zhuǎn)) <wbr>- <wbr>2        //構(gòu)造函數(shù)的默認(rèn)修飾為private
39反射(轉(zhuǎn)) <wbr>- <wbr>2        internal void TestObjectTypeNow(object A)
40反射(轉(zhuǎn)) <wbr>- <wbr>2        {
41反射(轉(zhuǎn)) <wbr>- <wbr>2            Type tpA A.GetType();
42反射(轉(zhuǎn)) <wbr>- <wbr>2            Assembly assembly tpA.Assembly;
43反射(轉(zhuǎn)) <wbr>- <wbr>2            Type[] types assembly.GetTypes();
44反射(轉(zhuǎn)) <wbr>- <wbr>2            foreach (Type type in types)
45反射(轉(zhuǎn)) <wbr>- <wbr>2            {
46反射(轉(zhuǎn)) <wbr>- <wbr>2                Console.WriteLine("【類名】"+type.FullName);
47反射(轉(zhuǎn)) <wbr>- <wbr>2                //獲取類型的結(jié)構(gòu)信息
48反射(轉(zhuǎn)) <wbr>- <wbr>2                ConstructorInfo[] myconstructors type.GetConstructors();
49反射(轉(zhuǎn)) <wbr>- <wbr>2                Show(myconstructors);
50反射(轉(zhuǎn)) <wbr>- <wbr>2                //獲取類型的字段信息
51反射(轉(zhuǎn)) <wbr>- <wbr>2                FieldInfo[] myfields type.GetFields();
52反射(轉(zhuǎn)) <wbr>- <wbr>2                Show(myfields);
53反射(轉(zhuǎn)) <wbr>- <wbr>2                //獲取方法信息
54反射(轉(zhuǎn)) <wbr>- <wbr>2                MethodInfo[] myMethodInfo type.GetMethods();
55反射(轉(zhuǎn)) <wbr>- <wbr>2                Show(myMethodInfo);
56反射(轉(zhuǎn)) <wbr>- <wbr>2                //獲取屬性信息
57反射(轉(zhuǎn)) <wbr>- <wbr>2                PropertyInfo[] myproperties type.GetProperties();
58反射(轉(zhuǎn)) <wbr>- <wbr>2                Show(myproperties);
59反射(轉(zhuǎn)) <wbr>- <wbr>2                //獲取事件信息,這個(gè)項(xiàng)目沒(méi)有事件,所以注釋掉了,
60反射(轉(zhuǎn)) <wbr>- <wbr>2                //通過(guò)這種辦法,還可以獲得更多的type相關(guān)信息.
61反射(轉(zhuǎn)) <wbr>- <wbr>2                //EventInfo[] Myevents type.GetEvents();
62反射(轉(zhuǎn)) <wbr>- <wbr>2                 //Show(Myevents);
63反射(轉(zhuǎn)) <wbr>- <wbr>2            }
64反射(轉(zhuǎn)) <wbr>- <wbr>2            Console.ReadLine();
65反射(轉(zhuǎn)) <wbr>- <wbr>2        }
66反射(轉(zhuǎn)) <wbr>- <wbr>2        //顯示數(shù)組的基本信息
67反射(轉(zhuǎn)) <wbr>- <wbr>2        public void Show(object[] os)
68反射(轉(zhuǎn)) <wbr>- <wbr>2        {
69反射(轉(zhuǎn)) <wbr>- <wbr>2            foreach (object var in os)
70反射(轉(zhuǎn)) <wbr>- <wbr>2            {
71反射(轉(zhuǎn)) <wbr>- <wbr>2                Console.WriteLine(var.ToString());
72反射(轉(zhuǎn)) <wbr>- <wbr>2            }
73反射(轉(zhuǎn)) <wbr>- <wbr>2            Console.WriteLine("----------------------------------");
74反射(轉(zhuǎn)) <wbr>- <wbr>2        }
75反射(轉(zhuǎn)) <wbr>- <wbr>2    }
76反射(轉(zhuǎn)) <wbr>- <wbr>2}

【注】通過(guò)測(cè)試,發(fā)現(xiàn)只能獲得public類型的信息.

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多