TypeInfo.DeclaredMethods 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得目前類型所定義之方法的集合。
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 方法周遊繼承樹狀結構。 來自自定義反映內容的物件取用者無法使用這些方法,而且必須周游繼承樹狀結構本身。