欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

復(fù)制代碼 代碼如下:

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:
復(fù)制代碼 代碼如下:

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:
復(fù)制代碼 代碼如下:

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: ********


相關(guān)文章

  • C#使用有道ip地址查詢接口方法實例詳解

    C#使用有道ip地址查詢接口方法實例詳解

    這篇文章主要介紹了C#使用有道ip地址查詢接口方法,實例分析了有道IP地址查詢接口的使用方法與數(shù)據(jù)返回格式,需要的朋友可以參考下
    2015-05-05
  • C#使用Dns類實現(xiàn)查詢主機(jī)名對應(yīng)IP地址

    C#使用Dns類實現(xiàn)查詢主機(jī)名對應(yīng)IP地址

    C#中的Dns類能夠與默認(rèn)的DNS服務(wù)器進(jìn)行通信,以檢索IP地址,這篇文章主要介紹了C#如何使用Dns類解析出主機(jī)對應(yīng)的IP地址信息,需要的可以參考下
    2024-02-02
  • 如何在C#中集成Lua腳本

    如何在C#中集成Lua腳本

    這篇文章主要介紹了如何在C#中集成Lua腳本,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-02-02
  • C#反射調(diào)用拓展類方法實例代碼

    C#反射調(diào)用拓展類方法實例代碼

    這篇文章主要給大家介紹了關(guān)于C#反射調(diào)用拓展類方法的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2022-01-01
  • C#實現(xiàn)如何使用短信平臺自動通知用戶實例

    C#實現(xiàn)如何使用短信平臺自動通知用戶實例

    這篇文章主要介紹了C#實現(xiàn)如何使用短信平臺自動通知用戶實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • C#中38個常用運算符的優(yōu)先級的劃分和理解

    C#中38個常用運算符的優(yōu)先級的劃分和理解

    這只我自己在學(xué)C#中的一些總結(jié),其中對于各級的劃分方式、各操作符的優(yōu)先級的理解并不見得正確,只是自己的看法,拿出來與大家分享
    2012-08-08
  • C#讀取系統(tǒng)字體顏色與大小的方法

    C#讀取系統(tǒng)字體顏色與大小的方法

    這篇文章主要介紹了C#讀取系統(tǒng)字體顏色與大小的方法,較為詳細(xì)的分析了C#獲取系統(tǒng)字體顏色與大小的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • .NET?MemoryCache如何清除全部緩存

    .NET?MemoryCache如何清除全部緩存

    本文主要介紹了.NET?MemoryCache如何清除全部緩存,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • C#通過屬性名稱獲取(讀取)屬性值的方法

    C#通過屬性名稱獲取(讀取)屬性值的方法

    本文主要介紹了C#通過屬性名稱獲取(讀取)屬性值的方法,并提供了簡化版代碼,具有很好的參考價值,需要的朋友可以看下
    2016-12-12
  • C#/VB.NET創(chuàng)建PDF文檔的示例代碼

    C#/VB.NET創(chuàng)建PDF文檔的示例代碼

    通過代碼創(chuàng)建 PDF 文檔有許多好處,所以本文將為大家詳細(xì)介紹一下如何使用 Spire.PDF for .NET 在 C# 和 VB.NET 中從頭開始創(chuàng)建 PDF 文檔,需要的可以參考下
    2023-12-12

最新評論