在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System;
using System.Reflection;
namespace TestReflect
{
class BaseClass
{
public int MyFieldBase=1;
public int getfieldBase()
{ return MyFieldBase; }
}
class DerivedClass : BaseClass
{
public int MyFieldDerived=2;
public int getfieldBase(int i)
{ return MyFieldDerived; }
}
class Program
{
static void Main(string[] args)
{
Type tbc=typeof(DerivedClass);
Console.WriteLine("类型名:{0}.", tbc.Name);
Console.WriteLine("它有如下字段:");
FieldInfo[] fi = tbc.GetFields();
MethodInfo[] me = tbc.GetMethods();
foreach (var f in fi)
{
Console.WriteLine("字段类型{0},字段名{1}",f.FieldType,f.Name);
}
Console.WriteLine();
Console.WriteLine("它有如下方法:");
foreach (var f in me)
{
Console.WriteLine("返回值类型:{0},函数名:{1}",f.ReturnType ,f.Name);
ParameterInfo[] paramsInfo = f.GetParameters();
foreach (var p in paramsInfo)
{
Console.WriteLine("参数类型:{0}参数名:{1}",p.ParameterType,p.Name);
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论