TypeInfo.DeclaredMethods 屬性


取得目前類型所定義之方法的集合。Gets a collection of the methods defined by the current type.

 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)



目前類型所定義之方法的集合。A collection of the methods defined by the current type.


此範例會在 .NET 中使用 Windows 8. x 商店應用程式子集的反映類型和成員,來取得類型的方法和屬性 Calendar ,包括繼承的方法和屬性。This example uses the reflection types and members in the .NET for Windows 8.x Store apps subset to retrieve the methods and properties of the Calendar type, including inherited methods and properties. 若要執行此程式碼,請將它貼入 Windows 8. x 存放區 XAML 應用程式的程式碼檔案,其中包含名為的 Textblock textblock1 控制項。To run this code, paste it into the code file for a Windows 8.x Store XAML app that contains a Windows.UI.Xaml.Controls.Textblock control named textblock1.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Navigation;
using System.Reflection;
using System.Globalization;
using System.Text;

namespace Reflection
    public sealed partial class MainPage : Page
        public MainPage()

        protected override void OnNavigatedTo(NavigationEventArgs e)
            TypeInfo t = typeof(Calendar).GetTypeInfo();
            IEnumerable<PropertyInfo> pList = t.DeclaredProperties;
            IEnumerable<MethodInfo> mList = t.DeclaredMethods;

            StringBuilder sb = new StringBuilder();
            foreach (PropertyInfo p in pList)

                sb.Append("\n" + p.DeclaringType.Name + ": " + p.Name);
            foreach (MethodInfo m in mList)
                sb.Append("\n" + m.DeclaringType.Name + ": " + m.Name);
            textblock1.Text = sb.ToString();
Imports Windows.UI.Xaml.Navigation
Imports System.Reflection
Imports System.Globalization
Imports System.Text

Public NotInheritable Class MainPage
    Inherits Page

    Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
        Dim t As TypeInfo = GetType(Calendar).GetTypeInfo()
        Dim pList As IEnumerable(Of PropertyInfo) = t.DeclaredProperties
        Dim mList As IEnumerable(Of MethodInfo) = t.DeclaredMethods

        Dim sb As New StringBuilder()

        For Each p As PropertyInfo In pList

            sb.Append((vbLf + p.DeclaringType.Name & ": ") + p.Name)
        sb.Append(vbLf & "Methods:")
        For Each m As MethodInfo In mList
            sb.Append((vbLf + m.DeclaringType.Name & ": ") + m.Name)

        textblock1.Text = sb.ToString()

    End Sub
End Class


若要篩選屬性的結果 DeclaredMethods ,請使用 LINQ 查詢。To filter the results of the DeclaredMethods property, use LINQ queries. 針對源自執行時間的反映物件 (例如,由於) 的結果, typeof(Object) 您可以使用類別中的方法來遍歷繼承樹狀結構 RuntimeReflectionExtensionsFor reflection objects that originate with the runtime (for example, as the result of typeof(Object)), you can traverse the inheritance tree by using the methods in the RuntimeReflectionExtensions class. 來自自訂反映內容之物件的取用者不能使用這些方法,而且必須自行遍歷繼承樹狀結構。Consumers of objects from customized reflection contexts cannot use these methods and must traverse the inheritance tree themselves.