PropertyInfo.PropertyType Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the type of this property.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public MustOverride ReadOnly Property PropertyType As Type
public abstract Type PropertyType { get; }

Property Value

Type: System.Type
The type of this property.

Remarks

The Type is String, Boolean, Int32, and so on.

To get the PropertyType property, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, get the PropertyType value.

Examples

The following example displays the type of a property.

Imports System.Reflection

Public Class Example
    Public ReadOnly Property Answer() As Integer
        Get
            Return 42
        End Get
    End Property

    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
        ' Get a Type object for the Example type.
        Dim t As Type = GetType(Example)

        ' Get a PropertyInfo object for the Answer property.
        Dim pi As PropertyInfo = t.GetProperty("Answer")

        ' Display the type returned by the Answer property.
        outputBlock.Text &= String.Format("The return type of the {0}.{1} property is {2}.", _
             t.Name, pi.Name, pi.PropertyType) & vbCrLf

    End Sub
End Class

' This example produces the following output:
'
'The return type of the Example.Answer property is System.Int32.
using System;
using System.Reflection;

public class Example
{
    public int Answer
    {
        get
        {
            return 42;
        }
    }

    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        // Get a Type object for the Example type.
        Type t = typeof(Example);

        // Get a PropertyInfo object for the Answer property.
        PropertyInfo pi = t.GetProperty("Answer");

        // Display the type returned by the Answer property.
        outputBlock.Text += String.Format("The return type of the {0}.{1} property is {2}.",
             t.Name, pi.Name, pi.PropertyType) + "\n";
    }
}

/* This example produces the following output:

The return type of the Example.Answer property is System.Int32.
 */

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.