My current code is like this;
This is so I can use the bar class in a number of different places in my code, and get my results back depending on the delegate I pass in.
All Straight forwards so far.
However, I am having to do a lot of Handling of object casting to and from different classes.
This set me to thinking about using Generics. Logically, I was expecting to be able to use something like;
However, when I try to build code like the above, I get an error on the line where I declare the delegate within class foo. (i.e. public delegateMethodType MethodToExecute)
So, the 6 million dollar question is, how do I represent a generic method in such a way?
(If it helps the error message I have is using the Generic Type ... reguires 1 Type arguments )
Thanks
K
Code:
class foo
{
public delegate object delegateMethodType(string s);
public delegateMethodType MethodToExecute;
public object DoWork(string s)
{
MethodToExecute(s);
...
...
}
}
class bar
{
foo f = new foo();
f.MethodToExecute = SomeMethod;
MyClass o = (MyClass)f.DoSomeWork("data");
}
This is so I can use the bar class in a number of different places in my code, and get my results back depending on the delegate I pass in.
All Straight forwards so far.
However, I am having to do a lot of Handling of object casting to and from different classes.
This set me to thinking about using Generics. Logically, I was expecting to be able to use something like;
Code:
class foo
{
public delegate T delegateMethodType<T>(string s);
public delegateMethodType MethodToExecute;
public T DoWork<T>(string s)
{
MethodToExecute(s);
...
...
}
}
class bar
{
foo f = new foo();
f.MethodToExecute = SomeMethod;
MyClass o = f.DoSomeWork<MyClass>("data");
}
However, when I try to build code like the above, I get an error on the line where I declare the delegate within class foo. (i.e. public delegateMethodType MethodToExecute)
So, the 6 million dollar question is, how do I represent a generic method in such a way?
(If it helps the error message I have is using the Generic Type ... reguires 1 Type arguments )
Thanks
K