M
Mr. X.
Is there any way to use shared method from non-shared one in the same class
?
Problem is :
I am running by code the defaultEventHandler, and the defaultEventHandler
should be declared as shared (compiler force me).
As the following code :
===============
Private Sub setDefaultEvents(byVal c as control)
Dim i As Integer
Dim c As Control
Dim d As DefaultEventAttribute
Dim ei As EventInfo
Dim mi As MethodInfo
Dim de As [Delegate]
For Each att In c.GetType.GetCustomAttributes(True)
If TypeOf att Is DefaultEventAttribute Then
d = att
ei = c.GetType.GetEvent(d.Name)
mi = Me.GetType.GetMethod("defaultEventHndlr")
de = [Delegate].CreateDelegate(ei.EventHandlerType, mi)
ei.AddEventHandler(c, de)
End If
Next
End Sub
Private Shared Sub defaultEventHndlr(ByVal sender As System.Object,
ByVal e As System.EventArgs)
... '**** I cannot call any other method of the current class, that is
not shareable.
End sub
The problem is marked in asterisks !
The class has it's own components, and I cannot write a new instance to use
any of the methods with no problems.
Is there any design-pattern, or any solution for the above?
Thanks
?
Problem is :
I am running by code the defaultEventHandler, and the defaultEventHandler
should be declared as shared (compiler force me).
As the following code :
===============
Private Sub setDefaultEvents(byVal c as control)
Dim i As Integer
Dim c As Control
Dim d As DefaultEventAttribute
Dim ei As EventInfo
Dim mi As MethodInfo
Dim de As [Delegate]
For Each att In c.GetType.GetCustomAttributes(True)
If TypeOf att Is DefaultEventAttribute Then
d = att
ei = c.GetType.GetEvent(d.Name)
mi = Me.GetType.GetMethod("defaultEventHndlr")
de = [Delegate].CreateDelegate(ei.EventHandlerType, mi)
ei.AddEventHandler(c, de)
End If
Next
End Sub
Private Shared Sub defaultEventHndlr(ByVal sender As System.Object,
ByVal e As System.EventArgs)
... '**** I cannot call any other method of the current class, that is
not shareable.
End sub
The problem is marked in asterisks !
The class has it's own components, and I cannot write a new instance to use
any of the methods with no problems.
Is there any design-pattern, or any solution for the above?
Thanks