对C#中MetaData的理解

MetaData就是用System.reflection得到的方法,属性,参数等等,这些都是元数据。

using System;
using System.Collections.Generic;
using System.Text;

using System.Reflection;

using System;

namespace MetaData
{
    class Program
    {
 static void Main(string[] args)
        {
            #region static class
            //Type t = Type.GetType("MetaData.Car");
            //ListMethod(t);
            #endregion

            #region dynamic class
            //string strPath = @"E:\HandsOn\IPC\KeepAlive\bin\Debug";
            //string strFile = string.Format(@"{0}\{1}", strPath,

"Service_RemotingInterface.dll");
            //Assembly asm = Assembly.LoadFrom(strFile);
            //DisplayTypeInAsm(asm);
            #endregion

 

            Console.ReadLine();
        }

        static void ListMethod(Type t)
        {
            MethodInfo[] mis = t.GetMethods();
            foreach (MethodInfo mi in mis)
            {
                Console.WriteLine("->{0}", mi.Name);
                Console.WriteLine();
            }
        }

        static void DisplayTypeInAsm(Assembly asm)
        {
            Console.WriteLine("\n***** Types in Assembly *****");
            Console.WriteLine("->{0}", asm.FullName);

            Type[] types = asm.GetTypes();
            foreach (Type type in types)
            {
                Console.WriteLine("Type: {0}", type);

                Console.WriteLine();
            }

        }
}

public class Car
    {
        public enum CarType { type1, type2, type3 };

        string _name = "Name1";
        CarType _type = CarType.type1;

        public string GetCarName()
        {
            return _name;
        }

        public CarType GetCarType()
        {
            return _type;
        }

 

    }


The output's example:
->GetCarName()
->GetCarType()
这两个函数就是Meta Data.

如果理解有误,欢迎更正。

转载于:https://www.cnblogs.com/Ruli/p/3873526.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值