Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1041422
  • 博文数量: 264
  • 博客积分: 6005
  • 博客等级: 大校
  • 技术积分: 2798
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-08 20:15
文章分类

全部博文(264)

文章存档

2011年(42)

2010年(213)

2009年(4)

2008年(2)

2007年(3)

分类: 嵌入式

2011-06-08 22:55:42

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Reflection;


  5. namespace ConsoleApplication1
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string className = "";
  12.             Console.WriteLine("请输入类名(比如System.Int32):");
  13.             className = Console.ReadLine();
  14.             try
  15.             {
  16.                 Type type = Type.GetType(className);
  17.                 Console.WriteLine("类型名:" + type.Name);
  18.                 Console.WriteLine("类的全名:" + type.FullName);
  19.                 Console.WriteLine("命名空间名:" + type.Namespace);
  20.                 Console.WriteLine("程序集名:" + type.Assembly);
  21.                 Console.WriteLine("模块名:" + type.Module);
  22.                 Console.WriteLine("基类名:" + type.BaseType);
  23.                 Console.WriteLine("运行时映射的类名:" + type.UnderlyingSystemType);
  24.                 Console.WriteLine("是否类:" + type.IsClass);
  25.                 Console.WriteLine("是否借口:" + type.IsInterface);
  26.                 Console.WriteLine("是否抽象类:" + type.IsAbstract);
  27.                 Console.WriteLine("是否数组类:" + type.IsArray);
  28.                 Console.WriteLine("是否值类型:" + type.IsValueType);
  29.                 Console.WriteLine("是否基本类型:" + type.IsPrimitive);
  30.                 Console.WriteLine("类的公共成员:");
  31.                 MemberInfo[] mis = type.GetMembers();
  32.                 foreach (MemberInfo mi in mis)
  33.                 {
  34.                     Console.WriteLine("\t{0}:{1},成员名:{2}", mi.MemberType, mi,mi.Name);
  35.                 }
  36.                 
  37.             }
  38.             catch
  39.             {
  40.                 Console.WriteLine("给定的不是一个合法的类名");
  41.             }
  42.         }
  43.     }
  44. }
阅读(761) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~