对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.

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

posted @ 2014-07-28 17:05  Phoebe_me  阅读(1553)  评论(0编辑  收藏  举报