TypeInfo.DeclaredMethods 属性

定义

获取由当前类型定义的方法的集合。

public:
 virtual property System::Collections::Generic::IEnumerable<System::Reflection::MethodInfo ^> ^ DeclaredMethods { System::Collections::Generic::IEnumerable<System::Reflection::MethodInfo ^> ^ get(); };
public virtual System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo> DeclaredMethods { get; }
member this.DeclaredMethods : seq<System.Reflection.MethodInfo>
Public Overridable ReadOnly Property DeclaredMethods As IEnumerable(Of MethodInfo)

属性值

由当前类型定义的方法的集合。

示例

以下示例使用 .NET 中的反射类型和成员检索该类型的方法和属性 Calendar ,包括继承的方法和属性,然后将它们写入控制台。

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

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
*/

注解

若要筛选 属性的结果 DeclaredMethods ,请使用 LINQ 查询。 例如,对于源自运行时 (的反射对象,作为) 的结果 typeof(Object) ,可以使用 类中的 RuntimeReflectionExtensions 方法遍历继承树。 自定义反射上下文中的对象的使用者不能使用这些方法,必须自行遍历继承树。

适用于