フォーラム/インターネットで、(Public プロパティの)PropetryInfo オブジェクトが Private \ Protected Setter を持っているかどうかを明らかにする方法を検索しました...それはすべて無駄でした....私が見つけたすべての助けは、方法に関するものでしたプライベート セッターを持つパブリック プロパティの "Set" 値...
パブリック プロパティの PropertyInfo オブジェクトがあるかどうかを知りたいのですが、そのセッターが非パブリックかどうかはどうすればわかりますか?
例外処理ブロックで、PropertyInfo オブジェクトの GetValue を実行してから、同じ値を設定して SetValue を呼び出してみましたが、驚いたことに、うまく機能し、エラーが発生しませんでした。
ヘルプは非常に高く評価されます...
例えば
Public Class Class1
Public Property HasContextChanged() As Boolean
Get
Return _hasContextChanged
End Get
Protected Set(ByVal value As Boolean)
_hasContextChanged = value
End Set
End Property
Public Function CanWriteProperty(Optional ByVal propName As String = "HasContextChanged") As Boolean
Dim prInfo As PropertyInfo = Me.GetType.GetProperty(propName)
If prInfo Is Nothing Then Return False
If Not prInfo.CanWrite Then
Return False
Else
Try
Dim value As Object = prInfo.GetValue(ownObj, Nothing)
prInfo.SetValue(ownObj, value, Nothing) 'Works for Private Setter
Catch ex As Exception
Return False 'Not coming here whatsoever
End Try
End If
Return True
End Function
クラス終了
どうも
ヴィニ・サンケ。