zoukankan      html  css  js  c++  java
  • 《C#高级编程》读书笔记(十二):反射

    1,反射

        反射是一个普通术语,它描述了在运行过程中检查和处理程序元素的功能。

    2,System.Type类    

    using System;
    using System.Reflection;
    using System.Text;
    using System.Windows.Forms;
    
    namespace Demo
    {
        public class ClassAnalyzeType
        {
            static StringBuilder OutputText = new StringBuilder();
    
            public static void AnalyzeType(Type t)
            {
                AddToOutput("Type Name:" + t.Name);
                AddToOutput("Full Name:" + t.FullName);
                AddToOutput("Namespace:" + t.Namespace);
    
                Type tBase = t.BaseType;
                if (tBase != null)
                {
                    AddToOutput("Base Type:" + tBase.Name);
                }
    
                Type tUnderlyingSystem = t.UnderlyingSystemType;
                AddToOutput("tUnderlyingSystem:" + tUnderlyingSystem);
                AddToOutput("
    PUBLIC MEMBERS:");
                MemberInfo[] members = t.GetMembers();
                foreach (var memberInfo in members)
                {
                    AddToOutput(memberInfo.DeclaringType + " " + memberInfo.MemberType + " " + memberInfo.Name);
                }
                MessageBox.Show(OutputText.ToString(), "Analysis of type " + t.Name);
            }
    
            static void AddToOutput(string Text)
            {
                OutputText.Append("
    " + Text);
            }
        }
    }

    测试:

    Type t = typeof(int);
    ClassAnalyzeType.AnalyzeType(t);

    输出:

    3,Assembly类

        Assembly类在System.Reflection名称空间中定义,它运行访问给定程序集的元数据,它也包含可以加载和执行程序集的方法。

  • 相关阅读:
    P1541 乌龟棋 暴力DP
    HDU
    HDU-6608 Fansblog 数论 ,威尔逊定理,快速乘
    P3842 [TJOI2007]线段 思维 ,DP
    模板 BSGS
    Gym
    HDU
    HDU
    HDU
    P1095 守望者的逃离 暴力DP
  • 原文地址:https://www.cnblogs.com/khjian/p/5682663.html
Copyright © 2011-2022 走看看