public ref class TypeInfo abstract : System::Reflection::MemberInfo, System::Reflection::IReflectableType
public ref class TypeInfo abstract : Type, System::Reflection::IReflectableType
public abstract class TypeInfo : System.Reflection.MemberInfo, System.Reflection.IReflectableType
public abstract class TypeInfo : Type, System.Reflection.IReflectableType
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public abstract class TypeInfo : Type, System.Reflection.IReflectableType
type TypeInfo = class
inherit MemberInfo
interface IReflectableType
type TypeInfo = class
inherit Type
interface IReflectableType
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type TypeInfo = class
inherit Type
interface IReflectableType
Public MustInherit Class TypeInfo
Inherits MemberInfo
Implements IReflectableType
Public MustInherit Class TypeInfo
Inherits Type
Implements IReflectableType
TypeInfo
TypeInfo t = typeof(Calendar).GetTypeInfo();
IEnumerable<PropertyInfo> pList = t.DeclaredProperties;
IEnumerable<MethodInfo> mList = t.DeclaredMethods;
StringBuilder sb = new StringBuilder();
sb.Append("Properties:");
foreach (PropertyInfo p in pList)
sb.Append("\n" + p.DeclaringType.Name + ": " + p.Name);
sb.Append("\nMethods:");
foreach (MethodInfo m in mList)
sb.Append("\n" + m.DeclaringType.Name + ": " + m.Name);
Console.WriteLine(sb.ToString());
/* This code outputs the following text:
Properties:
Calendar: MinSupportedDateTime
Calendar: MaxSupportedDateTime
Calendar: AlgorithmType
Calendar: ID
Calendar: BaseCalendarID
Calendar: IsReadOnly
Calendar: CurrentEraValue
Calendar: Eras
Calendar: DaysInYearBeforeMinSupportedYear
Calendar: TwoDigitYearMax
Methods:
Calendar: get_MinSupportedDateTime
Calendar: get_MaxSupportedDateTime
Calendar: get_AlgorithmType
Calendar: get_ID
Calendar: get_BaseCalendarID
Calendar: get_IsReadOnly
Calendar: get_CurrentEraValue
Calendar: get_Eras
Calendar: get_DaysInYearBeforeMinSupportedYear
Calendar: get_TwoDigitYearMax
Calendar: set_TwoDigitYearMax
Calendar: Clone
Calendar: ReadOnly
Calendar: VerifyWritable
Calendar: SetReadOnlyState
Calendar: CheckAddResult
Calendar: Add
Calendar: AddMilliseconds
Calendar: AddDays
Calendar: AddHours
Calendar: AddMinutes
Calendar: AddMonths
Calendar: AddSeconds
Calendar: AddWeeks
Calendar: AddYears
Calendar: GetDayOfMonth
Calendar: GetDayOfWeek
Calendar: GetDayOfYear
Calendar: GetDaysInMonth
Calendar: GetDaysInMonth
Calendar: GetDaysInYear
Calendar: GetDaysInYear
Calendar: GetEra
Calendar: GetHour
Calendar: GetMilliseconds
Calendar: GetMinute
Calendar: GetMonth
Calendar: GetMonthsInYear
Calendar: GetMonthsInYear
Calendar: GetSecond
Calendar: GetFirstDayWeekOfYear
Calendar: GetWeekOfYearFullDays
Calendar: GetWeekOfYearOfMinSupportedDateTime
Calendar: GetWeekOfYear
Calendar: GetYear
Calendar: IsLeapDay
Calendar: IsLeapDay
Calendar: IsLeapMonth
Calendar: IsLeapMonth
Calendar: GetLeapMonth
Calendar: GetLeapMonth
Calendar: IsLeapYear
Calendar: IsLeapYear
Calendar: ToDateTime
Calendar: ToDateTime
Calendar: TryToDateTime
Calendar: IsValidYear
Calendar: IsValidMonth
Calendar: IsValidDay
Calendar: ToFourDigitYear
Calendar: TimeToTicks
Calendar: GetSystemTwoDigitYearSetting
从 .NET Framework 4.5 开始,
TypeInfo
类包含在 .NET for Windows 8.x 应用商店应用子集中,用于创建 Windows 应用商店应用。
TypeInfo
在完整.NET Framework中也可用。 有关 Windows 应用商店应用的反射的详细信息,请参阅
Windows 应用商店应用的.NET Framework中的
System.Reflection 命名空间
和反射。
TypeInfo
包含 类中
Type
提供的许多成员,Windows 8.x 应用商店应用的 .NET 中的许多反射属性返回 对象的集合
TypeInfo
。 若要从 对象获取
TypeInfo
Type
对象,请使用
IntrospectionExtensions.GetTypeInfo(Type)
扩展方法。
对象
TypeInfo
表示类型定义本身,而
Type
对象表示对类型定义的引用。
TypeInfo
获取 对象会强制加载包含该类型的程序集。 相比之下,可以操作
Type
对象,而无需运行时加载它们引用的程序集。
在 Windows 8.x 应用商店应用的 .NET 中,使用返回
IEnumerable<T>
集合的
TypeInfo
反射属性,而不是返回数组的方法。 例如,使用
DeclaredMembers
属性获取所有声明的成员,或使用
DeclaredProperties
属性获取所有声明的属性。 反射上下文可以实现这些大型程序集或类型集合的延迟遍历。 若要获取特定成员,请使用 和
GetDeclaredProperty
等
GetDeclaredMethod
方法,并传递要检索的方法或属性的名称。
若要筛选属性的结果
TypeInfo
,请使用 LINQ 查询。 例如,对于源自运行时 (的反射对象,作为) 的结果
typeof(Object)
,可以使用 类中的
RuntimeReflectionExtensions
方法遍历继承树。 自定义反射上下文中的对象的使用者不能使用这些方法,必须自行遍历继承树。