|
■No5588 (yamyam さん) に返信 > デリゲートを使用したコードを作成していたときに思ったのですが、 > Propertyのgetter/setterにはデリゲートを適用できないのでしょうか?
# 「デリゲートを適用する」というのが、どういう状態を指すのか掴みきれなかったので…外してるかも。
Public Class Form1 Private _SampleProperty As Integer = 777 Public Property SampleProperty() As Integer Set(ByVal value As Integer) _SampleProperty = value End Set Get Return _SampleProperty End Get End Property
Delegate Sub PropSetDelegate(ByVal value As Integer) Delegate Function PropGetDelegate() As Integer
Private setter As PropSetDelegate Private getter As PropGetDelegate
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load With Me.GetType().GetProperty("SampleProperty") getter = DirectCast([Delegate].CreateDelegate(GetType(PropGetDelegate), _ Me, .GetGetMethod(True)), PropGetDelegate) setter = DirectCast([Delegate].CreateDelegate(GetType(PropSetDelegate), _ Me, .GetSetMethod(True)), PropSetDelegate) End With End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Me.SampleProperty = 1234 Trace.WriteLine(Me.SampleProperty) Trace.WriteLine(getter()) setter(9876) Trace.WriteLine(Me.SampleProperty) Trace.WriteLine(getter()) End Sub End Class
|