PropertyInfo.Attributes プロパティ
このプロパティの属性を取得します。
Public MustOverride ReadOnly Property Attributes As _
PropertyAttributes
[C#]
public abstract PropertyAttributes Attributes {get;}
[C++]
public: __property virtual PropertyAttributes get_Attributes() = 0;
[JScript]
public abstract function get Attributes() : PropertyAttributes;
プロパティ値
このプロパティの属性。
解説
このプロパティは、メンバに関連付けられた属性を表します。すべてのメンバが属性のセットを持っています。属性は、メンバの特定の型との関係で定義されます。プロパティ属性によって、ユーザーはこのプロパティが既定のプロパティかどうか、 SpecialName プロパティかどうかなどを知ることができます。
Attributes プロパティを取得するには、最初に Type クラスを取得します。そして、その Type から PropertyInfo を取得します。 PropertyInfo から属性を取得します。
使用例
指定したプロパティの属性を表示する例を次に示します。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class Myproperty
Private myCaption As String = "Default caption"
Public Property Caption() As String
Get
Return myCaption
End Get
Set(ByVal Value As String)
If myCaption <> value Then
myCaption = value
End If
End Set
End Property
End Class 'Myproperty
Class Mypropertyinfo
Public Shared Function Main() As Integer
Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyInfo")
' Define a property.
Dim Myproperty As New Myproperty()
Console.Write(ControlChars.CrLf & "Myproperty.Caption = " & _
Myproperty.Caption)
' Get the type and PropertyInfo.
Dim MyType As Type = Type.GetType("Myproperty")
Dim Mypropertyinfo As PropertyInfo = MyType.GetProperty("Caption")
' Get and display the attributes property.
Dim Myattributes As PropertyAttributes = Mypropertyinfo.Attributes
Console.Write(ControlChars.CrLf & "PropertyAttributes - " & _
Myattributes.ToString())
Return 0
End Function
End Class
[C#]
using System;
using System.Reflection;
public class Myproperty
{
private string caption = "Default caption";
public string Caption
{
get{return caption;}
set {if(caption!=value) {caption = value;}
}
}
}
class Mypropertyinfo
{
public static int Main(string[] args)
{
Console.WriteLine("\nReflection.PropertyInfo");
// Define a property.
Myproperty Myproperty = new Myproperty();
Console.Write("\nMyproperty.Caption = " + Myproperty.Caption);
// Get the type and PropertyInfo.
Type MyType = Type.GetType("Myproperty");
PropertyInfo Mypropertyinfo = MyType.GetProperty("Caption");
// Get and display the attributes property.
PropertyAttributes Myattributes = Mypropertyinfo.Attributes;
Console.Write("\nPropertyAttributes - " + Myattributes.ToString());
return 0;
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
public __gc class Myproperty
{
private:
String* caption;
public:
Myproperty() : caption(S"Default caption") {}
__property String* get_Caption() {
return caption;
}
__property void set_Caption(String* value) {
if(caption!=value) {
caption = value;
}
}
};
int main()
{
Console::WriteLine(S"\nReflection.PropertyInfo");
// Define a property.
Myproperty* myproperty = new Myproperty();
Console::Write(S"\nMyproperty->Caption = {0}", myproperty->Caption);
// Get the type and PropertyInfo.
Type* MyType = Type::GetType(S"Myproperty");
PropertyInfo* Mypropertyinfo = MyType->GetProperty(S"Caption");
// Get and display the attributes property.
PropertyAttributes Myattributes = Mypropertyinfo->Attributes;
Console::Write(S"\nPropertyAttributes - {0}", __box(Myattributes));
return 0;
}
[JScript]
//Make a property, then display the PropertyInfo
import System;
import System.Reflection;
public class Myproperty
{
private var caption : String = "Default caption";
public function get Caption() : String {
return caption;
}
public function set Caption(value:String) {
if(caption!=value) caption = value;
}
}
class Mypropertyinfo
{
public static function Main() : void
{
Console.WriteLine("\nReflection.PropertyInfo");
//Build a property
var myproperty : Myproperty = new Myproperty();
Console.Write("\nMyproperty.Caption = " + myproperty.Caption);
//Get the type and PropertyInfo
var MyType : Type = Type.GetType("Myproperty");
var Mypropertyinfo : PropertyInfo = MyType.GetProperty("Caption");
//Get and display the attributes property
var Myattributes : PropertyAttributes = Mypropertyinfo.Attributes;
Console.Write("\nPropertyAttributes - " + Myattributes.ToString());
}
}
Mypropertyinfo.Main();
/*
Produces the following output
Reflection.PropertyInfo
Myproperty.Caption = Default caption
PropertyAttributes - None
*/
必要条件
プラットフォーム: 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 名前空間