码迷,mamicode.com
首页 > Windows程序 > 详细

C#中基于System.Type的反射

时间:2015-05-13 08:43:51      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Reflection
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "Hello Reflection";
            Type t = s.GetType();
            Console.WriteLine(t.FullName);

            Type t2 = Type.GetType("System.String",false,true);
            Console.WriteLine(t2.FullName);

            Type t3 = typeof(string);
            Console.WriteLine(t3.FullName);
          //  GetMehtods(t);

            Console.WriteLine("Join method:{0}",t.GetMethod("Copy"));

            GetMehtods(t,BindingFlags.Public|BindingFlags.Instance);

            //GetFields().GetProperites()
            Console.ReadLine();
        }
        public static void GetMehtods(Type t,BindingFlags f)
        {
            
            MethodInfo[] mi = t.GetMethods(f);
            foreach (MethodInfo m in mi)
            {
                Console.WriteLine("{0}",m.Name);
            }
        }
    }
}

 

C#中基于System.Type的反射

标签:

原文地址:http://www.cnblogs.com/heisaijuzhen/p/4499258.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!