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名称空间中定义,它运行访问给定程序集的元数据,它也包含可以加载和执行程序集的方法。

  • 相关阅读:
    DEM地形渲染中光源的方向
    python GDAL安装运行后提示找不到proj.db
    AO——将函数栅格数据集保存到磁盘
    arcgis影像分幅图裁剪
    arcgis判断线是否穿过面
    WSL 使用vscode写python
    python-gdal支持filegdb读写
    Chapter5 生长因子、受体和癌症
    Chapter6 胞内信号网络
    【转】B树、B+树、B*树
  • 原文地址:https://www.cnblogs.com/khjian/p/5682663.html
Copyright © 2011-2022 走看看