how to raise a non shared event from a shared method ?

  • Thread starter Thread starter Pon
  • Start date Start date
P

Pon

Hi everybody,

Simple question : Inside a class that has a shared method, how to raise an
event on a given instance of this class from the shared method ?
 
Just pass the instance variable to the shared method. Here's a working
example:

Module Module1

Sub Main()
Dim c As New YourClass
YourClass.ChangeName(c, "funny pants")
Console.WriteLine(c.Name)
Console.Read()
End Sub

End Module

Public Class YourClass

Private m_Name As String

Public Shared Sub ChangeName(ByVal c As YourClass, ByVal newName As
String)
c.Name = newName
End Sub

Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property

End Class

Thanks,

Seth Rowe
 
Pon said:
Simple question : Inside a class that has a shared method, how to raise an
event on a given instance of this class from the shared method ?

In order to do that you need a reference to an instance of the class. If
you implement the event using the .NET event pattern you can call the
corresponding protected 'On<event name>' method to raise the event.
 
Perfect and obvious. Thanx a lot.

Herfried K. Wagner said:
In order to do that you need a reference to an instance of the class. If
you implement the event using the .NET event pattern you can call the
corresponding protected 'On<event name>' method to raise the event.
 
Back
Top