PropertyInfo.GetSetMethod メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
このプロパティのset アクセサーを表すMethodInfoを返します。
オーバーロード
| 名前 | 説明 |
|---|---|
| GetSetMethod(Boolean) |
派生クラスでオーバーライドされると、このプロパティの |
| GetSetMethod() |
このプロパティのパブリック |
GetSetMethod(Boolean)
派生クラスでオーバーライドされると、このプロパティの set アクセサーを返します。
public:
abstract System::Reflection::MethodInfo ^ GetSetMethod(bool nonPublic);
public abstract System.Reflection.MethodInfo GetSetMethod(bool nonPublic);
abstract member GetSetMethod : bool -> System.Reflection.MethodInfo
Public MustOverride Function GetSetMethod (nonPublic As Boolean) As MethodInfo
パラメーター
- nonPublic
- Boolean
アクセサーがパブリックでない場合に返す必要があるかどうかを示します。
true 非パブリック アクセサーが返される場合。それ以外の場合は false。
返品
次の表に示すように、このプロパティの Set メソッドまたは null。
| 価値 | 条件 |
|---|---|
このプロパティの Set メソッド。
|
set アクセサーはパブリック、OR nonPublicはtrueされ、set アクセサーはパブリック以外です。
|
null |
nonPublic は trueですが、プロパティが読み取り専用であるか、OR nonPublic が false され、 set アクセサーが非パブリックであるか、 set アクセサーがありません。
|
実装
例外
要求されたメソッドは非パブリックであり、呼び出し元には、この非パブリック メソッドに反映する ReflectionPermission がありません。
例
次の例では、指定したプロパティの set アクセサーを表示します。
using System;
using System.Reflection;
// Define a property.
public class Myproperty
{
private string caption = "A Default caption";
public string Caption
{
get{return caption;}
set {if(caption!=value) {caption = value;}
}
}
}
class Mypropertyinfo
{
public static int Main()
{
Console.WriteLine ("\nReflection.PropertyInfo");
// Get the type and PropertyInfo for two separate properties.
Type MyTypea = Type.GetType("Myproperty");
PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Caption");
Type MyTypeb = Type.GetType("System.Text.StringBuilder");
PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("Length");
// Get and display the GetSetMethod method for each property.
MethodInfo Mygetmethodinfoa = Mypropertyinfoa.GetSetMethod();
Console.Write ("\nSetAccessor for " + Mypropertyinfoa.Name
+ " returns a " + Mygetmethodinfoa.ReturnType);
MethodInfo Mygetmethodinfob = Mypropertyinfob.GetSetMethod();
Console.Write ("\nSetAccessor for " + Mypropertyinfob.Name
+ " returns a " + Mygetmethodinfob.ReturnType);
// Display the GetSetMethod without using the MethodInfo.
Console.Write ("\n\n" + MyTypea.FullName + "."
+ Mypropertyinfoa.Name + " GetSetMethod - "
+ Mypropertyinfoa.GetSetMethod());
Console.Write ("\n" + MyTypeb.FullName + "."
+ Mypropertyinfob.Name + " GetSetMethod - "
+ Mypropertyinfob.GetSetMethod());
return 0;
}
}
Imports System.Reflection
' Define a property.
Public Class Myproperty
Private myCaption As String = "A 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
Class Mypropertyinfo
Public Shared Function Main() As Integer
Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyInfo")
' Get the type and PropertyInfo for two separate properties.
Dim MyTypea As Type = Type.GetType("Myproperty")
Dim Mypropertyinfoa As PropertyInfo = MyTypea.GetProperty("Caption")
Dim MyTypeb As Type = Type.GetType("System.Text.StringBuilder")
Dim Mypropertyinfob As PropertyInfo = MyTypeb.GetProperty("Length")
' Get and display the GetSetMethod method for each property.
Dim Mygetmethodinfoa As MethodInfo = Mypropertyinfoa.GetSetMethod()
Console.WriteLine("SetAccessor for " & Mypropertyinfoa.Name & _
" returns a " & Mygetmethodinfoa.ReturnType.ToString())
Dim Mygetmethodinfob As MethodInfo = Mypropertyinfob.GetSetMethod()
Console.WriteLine("SetAccessor for " & Mypropertyinfob.Name & _
" returns a " & Mygetmethodinfob.ReturnType.ToString())
' Display the GetSetMethod without using the MethodInfo.
Console.WriteLine(MyTypea.FullName & "." & Mypropertyinfoa.Name & _
" GetSetMethod - " & Mypropertyinfoa.GetSetMethod().ToString())
Console.WriteLine(MyTypeb.FullName & "." & Mypropertyinfob.Name & _
" GetSetMethod - " & Mypropertyinfob.GetSetMethod().ToString())
Return 0
End Function
End Class
注釈
GetSetMethod メソッドを使用するには、最初にクラス Typeを取得します。
Typeから、PropertyInfoを取得します。
PropertyInfoから、GetSetMethod メソッドを使用します。
適用対象
GetSetMethod()
このプロパティのパブリック set アクセサーを返します。
public:
virtual System::Reflection::MethodInfo ^ GetSetMethod();
public:
System::Reflection::MethodInfo ^ GetSetMethod();
public System.Reflection.MethodInfo GetSetMethod();
abstract member GetSetMethod : unit -> System.Reflection.MethodInfo
override this.GetSetMethod : unit -> System.Reflection.MethodInfo
member this.GetSetMethod : unit -> System.Reflection.MethodInfo
Public Function GetSetMethod () As MethodInfo
返品
set アクセサーがパブリックの場合は、このプロパティのSet メソッドを表すMethodInfo オブジェクト。set アクセサーがパブリックでない場合はnull。
実装
注釈
これは、nonPublic パラメーターを false に設定した抽象GetSetMethod メソッドの実装を提供する便利なメソッドです。
GetSetMethod メソッドを使用するには、最初にクラス Typeを取得します。
Typeから、PropertyInfoを取得します。
PropertyInfoから、GetSetMethod メソッドを使用します。