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

  • 相关阅读:
    K近邻法
    感知机
    统计学习方法概论
    神经网络的学习 Neural Networks learing
    对线性回归、逻辑回归、各种回归的概念学习
    从零开始创建VUE项目
    Java中Log4j.properties配置文件详解
    Java中Log4j的入门实例
    Java中Log4j的基本使用方法说明
    C#与Java的RSA中的X509EncodedKeySpec、PKCS8EncodedKeySpec
  • 原文地址:https://www.cnblogs.com/khjian/p/5682663.html
Copyright © 2011-2022 走看看