You can do this via Reflection, but it is less than obvious. If you declare an event in C#, a field will be added to the class with the event name + "Event". If you call GetValue on the field, it will return a MulticastDelegate instance.
Once you have the MulticastDelegate, you can get the invocation list, and invoke each member in turn:
EventArgs e = new EventArgs(myClassInstance); // Create appropriate EventArgs
MulticastDelegate eventDelagate =
this.GetType().GetField(theEventName + "Event",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic).GetValue(myClassInstance) as MulticastDelegate;
Delegate[] delegates = eventDelagate.GetInvocationList();
foreach (Delegate del in delegates) {
del.Method.Invoke(del.Target, new object[] { myClassInstance, e });
}
Note that this requires getting a NonPublic field from the instance, so it will only work in full trust, and is very limited.
Is it possible to create a generic Raise() that accepts the event to be raised as a parameter? therefore it would still be called from inside the class?
Yes. It would be fairly easy to modify the above code to do this. Just replace "myClassInstance" with this. This will actually allow this to work properly in full trust, as well, since the NonPublic BindingFlag will no longer be an issue.