PropertyInfo.PropertyType プロパティ
このプロパティの型を取得します。
Public MustOverride ReadOnly Property PropertyType As Type
[C#]
public abstract Type PropertyType {get;}
[C++]
public: __property virtual Type* get_PropertyType() = 0;
[JScript]
public abstract function get PropertyType() : Type;
プロパティ値
このプロパティの型。
解説
型は、String、 Boolean 、 Int32 などです。
PropertyType プロパティを取得するには、最初に Type クラスを取得します。そして、その Type から PropertyInfo を取得します。 PropertyInfo から PropertyType 値を取得します。
使用例
指定したプロパティのデータ型を表示する例を次に示します。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Class Mypropertyinfo
Public Shared Function Main() As Integer
Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyInfo")
' Get the type and PropertyInfo.
Dim MyTypea As Type = Type.GetType("System.Reflection.MemberInfo")
Dim Mypropertyinfoa As PropertyInfo = MyTypea.GetProperty("Name")
Dim MyTypeb As Type = Type.GetType("System.Reflection.MethodBase")
Dim Mypropertyinfob As PropertyInfo = MyTypeb.GetProperty("IsFinal")
' Read and display the PropertyType property.
Console.WriteLine(MyTypea.FullName & "." & Mypropertyinfoa.Name & _
" has a PropertyType of " & Mypropertyinfoa.PropertyType.ToString())
Console.WriteLine(MyTypeb.FullName & "." & Mypropertyinfob.Name & _
" has a PropertyType of " & Mypropertyinfob.PropertyType.ToString())
Return 0
End Function
End Class
[C#]
using System;
using System.Reflection;
class Mypropertyinfo
{
public static int Main()
{
Console.WriteLine("\nReflection.PropertyInfo");
// Get the type and PropertyInfo.
Type MyTypea = Type.GetType("System.Reflection.MemberInfo");
PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Name");
Type MyTypeb = Type.GetType("System.Reflection.MethodBase");
PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("IsFinal");
// Read and display the PropertyType property.
Console.Write ("\n" + MyTypea.FullName + "." + Mypropertyinfoa.Name +
" has a PropertyType of " + Mypropertyinfoa.PropertyType);
Console.Write("\n" + MyTypeb.FullName + "." + Mypropertyinfob.Name +
" has a PropertyType of " + Mypropertyinfob.PropertyType);
return 0;
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
int main()
{
Console::WriteLine(S"\nReflection.PropertyInfo");
// Get the type and PropertyInfo.
Type* MyTypea = Type::GetType(S"System.Reflection.MemberInfo");
PropertyInfo* Mypropertyinfoa = MyTypea->GetProperty(S"Name");
Type* MyTypeb = Type::GetType(S"System.Reflection.MethodBase");
PropertyInfo* Mypropertyinfob = MyTypeb->GetProperty(S"IsFinal");
// Read and display the PropertyType property.
Console::Write (S"\n{0}.{1} has a PropertyType of {2}",
MyTypea->FullName, Mypropertyinfoa->Name, Mypropertyinfoa->PropertyType);
Console::Write(S"\n{0}.{1} has a PropertyType of {2}",
MyTypeb->FullName, Mypropertyinfob->Name, Mypropertyinfob->PropertyType);
return 0;
}
[JScript]
import System;
import System.Reflection;
class Mypropertyinfo
{
public static function Main() : void
{
Console.WriteLine("\nReflection.PropertyInfo");
//Get the type and PropertyInfo
var MyTypea : Type = Type.GetType("System.Reflection.MemberInfo");
var Mypropertyinfoa : PropertyInfo = MyTypea.GetProperty("Name");
var MyTypeb : Type = Type.GetType("System.Reflection.MethodBase");
var Mypropertyinfob : PropertyInfo = MyTypeb.GetProperty("IsFinal");
//Read and display the PropertyType property
Console.Write ("\n" + MyTypea.FullName + "." + Mypropertyinfoa.Name +
" has a PropertyType of " + Mypropertyinfoa.PropertyType);
Console.Write("\n" + MyTypeb.FullName + "." + Mypropertyinfob.Name +
" has a PropertyType of " + Mypropertyinfob.PropertyType);
}
}
Mypropertyinfo.Main();
/*
Produces the following output
Reflection.PropertyInfo
System.Reflection.MemberInfo.Name has a PropertyType of System.String
System.Reflection.MethodBase.IsFinal has a PropertyType of Boolean
*/
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
PropertyInfo クラス | PropertyInfo メンバ | System.Reflection 名前空間