المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Multicast Delegate using MethodInfo



C# Programming
12-02-2009, 09:30 PM
Hello Everybody,

I want to create multicast delegates automatically. I am working on a solution with Attributes on methods. The plan is to have a method, that takes a few objects and creates a multicast delegate from all methods that have a certain Attribute.

In the following example I want the method ConformsToMyMulticast to be added to the multicast (because it is marked with MyAttribute).

class Program {

public delegate void MyMulticast();

static void Main(string[] args)
{
MyMulticast multi;
Test t1 = new Test();
MethodInfo[] methodList = t1.GetType().GetMethods();

foreach (MethodInfo info in methodList)
{
foreach (object o in info.GetCustomAttributes(true))
{
if (o is MyAttribute)
{
//TODO This is where I need help
multi += info ???
}
} } }
}

class Test
{
public Test() {}

[MyAttribute()]
public void ConformsToMyMulticast() {}
}


I've been working on that for the last few hours and I really hope one of you can help me.
Thanks in advance!