Well I don't know if anyone is interested in this but I have finally found a solution for this.
public class BaseObject
{
public event EventHandler Event1;
private BindingFlags flags = BindingFlags.NonPublic |BindingFlags.Instance | BindingFlags.Public;
public BaseObject(){}
public void ReleaseEvents()
{
//Get all of the events and then use the DeclaringType property to get the instance of the fields
EventInfo[] events = this.GetType().GetEvents(flags);
if(events == null)
return;
if(events.Length < 1)
return;
//Store All the FieldInfo objects in a HashTable
System.Collections.Hashtable ht = new System.Collections.Hashtable();
for(int i = 0; i < events.Length; i++)
{
//Get all of the fields for the selected declared type
FieldInfo[] fields = events[i].DeclaringType.GetFields(flags);
foreach(FieldInfo fi in fields)
{
if(events[i].Name.Equals(fi.Name) && !ht.Contains(fi.Name))
ht.Add(fi.Name,fi);
}
}
System.Collections.IDictionaryEnumerator en = ht.GetEnumerator();
while(en.MoveNext())
{
FieldInfo f = en.Value as FieldInfo;
MulticastDelegate e = f.GetValue(this) as MulticastDelegate;
if(e != null)
{
foreach(Delegate del in e.GetInvocationList())
{
getEvent(f.Name,f.DeclaringType).GetRemoveMethod().Invoke(this,new object[]{del});
}
}
}
}
private EventInfo getEvent(string name, Type t)
{
if(name == null)
return null;
if(t == null)
return null;
return t.GetEvent(name,flags);
}
public string Name
{
get{return Guid.NewGuid().ToString();}
set
{
Event1(this,null);
}
}