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

如何利用反射構(gòu)建元數(shù)據(jù)查看器

 更新時間:2013年06月08日 11:50:04   作者:  
本篇文章是對反射構(gòu)建元數(shù)據(jù)查看器進行了詳細的分析介紹,需要的朋友參考下

原理比較簡單,引入System.Reflection命名空間,利用反射查看某種Type下的方法,屬性,字段和支持的接口等。

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Data.SqlClient;
using System.Xml;
using System.Data;
using System.Reflection;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Please input a type:");
                string typeStr = Console.ReadLine();

                if (typeStr == "exit" || typeStr == "quit")
                    break;

                try
                {
                    Type type = Type.GetType(typeStr);
                    ListFields(type);
                    ListMethods(type);
                    ListInterfaces(type);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("It is not a valid type!");
                }
            }

        }

        #region Methods
        public static void ListFields(Type type)
        {
            Console.WriteLine("******** Fields: ********");
            //foreach (FieldInfo item in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Default))
            foreach (FieldInfo item in type.GetFields())
            {
                Console.WriteLine("->" + item.Name);
            }
            Console.WriteLine("");
        }

        public static void ListMethods(Type type)
        {
            Console.WriteLine("******** Methods: ********");
            //foreach (var item in type.GetMethods(BindingFlags.Default | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic))
            var methodInfo = type.GetMethods().Select(m => m.Name).Distinct();
            foreach (var item in methodInfo)
            {
                Console.WriteLine("->" + item);
            }
            Console.WriteLine("");
        }

        public static void ListInterfaces(Type type)
        {
            Console.WriteLine("******** Interfaces: ********");
            foreach (var item in type.GetInterfaces())
            {
                Console.WriteLine("->" + item.Name);
            }
            Console.WriteLine("");
        }

        public static void ListProperties(Type type)
        {
            Console.WriteLine("******** Properties: ********");
            foreach (var item in type.GetProperties())
            {
                Console.WriteLine("->" + item.Name);
            }
            Console.WriteLine("");
        }
        #endregion

    }

}


測試case 1:
復制代碼 代碼如下:

Please input a type:
System.Int32
******** Fields: ********
->MaxValue
->MinValue

******** Methods: ********
->CompareTo
->Equals
->GetHashCode
->ToString
->Parse
->TryParse
->GetTypeCode
->GetType

******** Interfaces: ********
->IComparable
->IFormattable
->IConvertible
->IComparable`1
->IEquatable`1


測試case 2:
復制代碼 代碼如下:

Please input a type:
System.Math
******** Fields: ********
->PI
->E

******** Methods: ********
->Acos
->Asin
->Atan
->Atan2
->Ceiling
->Cos
->Cosh
->Floor
->Sin
->Tan
->Sinh
->Tanh
->Round
->Truncate
->Sqrt
->Log
->Log10
->Exp
->Pow
->IEEERemainder
->Abs
->Max
->Min
->Sign
->BigMul
->DivRem
->ToString
->Equals
->GetHashCode
->GetType

******** Interfaces: ********


相關文章

最新評論

怀来县| 星座| 岱山县| 三门峡市| 东至县| 两当县| 揭东县| 肃北| 洪湖市| 宜丰县| 临夏市| 女性| 绥中县| 南澳县| 泸定县| 阿图什市| 哈尔滨市| 县级市| 达尔| 利辛县| 随州市| 平顶山市| 禹城市| 昌乐县| 平果县| 江川县| 叙永县| 泸州市| 将乐县| 阿巴嘎旗| 滨海县| 佛学| 万源市| 阳东县| 长岛县| 夏河县| 淮滨县| 凤阳县| 娱乐| 古蔺县| 浮山县|