Home All Groups Group Topic Archive Search About

Reflection and Interfaces

Author
23 Feb 2007 7:07 PM
Random
I'm sure this has got to be something simple, but if someone could help
shortcut me on this, I'd be very grateful.

I have a set of classes that implement my interface IGenericInference.
Some of the classes have an event that gets raised when one of the interface
properties changes.  I then have a super-class that uses several of these
interface-based classes as properties.  My goal is to have a handler that
will capture the event and be able to identify the property of the
super-class that has changed and be able to perform an operation on it.
Here's some trimmed down code...

Public Interface IGenericInference
    Property ID() As Long
    Property Description() As String
End Interface

Public Class A
    Implements IGenericInference

    Private mlngid As Long
    Private mstrDescription As String

    Public Event ID_Changed(ByVal sender As IGenericInference)

    Public Property ID() As Long Implements IGenericInference.ID
        Get
            Return mlngid
        End Get
        Set(ByVal value As Long)
            If Not mlngid = value Then
                mlngid = value
                RaiseEvent ID_Changed(Me)
            End If
        End Set
    End Property

    Public Property Description() As String Implements
IGenericInference.Description
        Get
            Return mstrDescription
        End Get
        Protected Set(ByVal value As String)
            mstrDescription = value
        End Set
    End Property
End Class

Public Class B
    (identical for purposes here to Class A)
End Class

Public Class SuperClass
    Private mobjClassA As A
    Private mobjClassB As B

    Public Property Foo1 As A
        Get
            Return mobjClassA
        End Get
        Set(ByVal value As A)
            mobjClassA = value
        End Set
    End Property

    Public Property Foo2 As B
        Get
            Return mobjClassB
        End Get
        Set(ByVal value As B)
            mobjClassB = value
        End Set
    End Property

    Public Event GenID_Changed(ByVal sender As IGenericInference)

    Private Sub ID_Changed(ByVal sender As IGenericInference) Handles
mobjClassA.ID_Changed, mobjClassB.ID_Changed
        RaiseEvent TypeID_Changed(sender)
    End Sub
End Class

Public Class InheritedSuperClass
    Inherits SuperClass

    Private Sub MyHandler(ByVal sender as IGenericInference) Handles
Me.GenID_Changed
        (here I want to determine which property (Foo1 or Foo2) on the base
class matches the type of sender(class A or class B) so that I can do
something with that property; I need to use reflection and not just straight
comparison)
    End Sub
End Class

AddThis Social Bookmark Button