TypeInfo.DeclaredProperties 属性


获取由当前类型定义的属性的集合。Gets a collection of the properties defined by the current type.

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


由当前类型定义的属性的集合。A collection of the properties defined by the current type.


此示例使用 适用于 Windows 8.x 应用商店应用的 .NET.NET for Windows 8.x Store apps 子集中的反射类型和成员来检索 Calendar 类型的方法和属性,包括继承的方法和属性。This example uses the reflection types and members in the 适用于 Windows 8.x 应用商店应用的 .NET.NET for Windows 8.x Store apps subset to retrieve the methods and properties of the Calendar type, including inherited methods and properties. 若要运行此代码,请将其粘贴到包含名为 textblock1Textblock控件的 Windows 8.x 应用商店Windows 8.x Store XAML 应用的代码文件中。To run this code, paste it into the code file for a Windows 8.x 应用商店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