using System;
using System.Reflection;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Type myType = typeof(People);
Console.WriteLine(myType.Name);//获取类的名字
Console.WriteLine(myType.FullName);//获取类的全字
Console.WriteLine(myType.BaseType.Name);//获取基类名字
Console.WriteLine(myType.IsClass);//是否是类
PropertyInfo[] propertyInfos = myType.GetProperties();//获取属性
MethodInfo[] methodInfos = myType.GetMethods();//获取方法
foreach (PropertyInfo item in propertyInfos)
{
Console.WriteLine(item.Name);
}
foreach (MethodInfo item in methodInfos)
{
Console.WriteLine(item.Name);
}
}
}
class People
{
public string Name { get; set; }
public int Heigth { get; set; }
public double Rich { get; set; }
}
}
C#获取类的名字、属性名字、方法名字的方式
于 2022-02-20 11:01:00 首次发布