G
Gene Vital
Hi all,
I need some help in understanding how to use Generics. I have a class
based on a user control that can be put on any Container at runtime, I
want to be able to call a method on the parent class without knowing the
type of the parent class, can this be done with C#?
I thought this was what Generics was supposed to be all about but I have
spent the whole day Googling and I can't find a way to do this in C#.
An example would be
public class MyClass : UserControl
{
public void SomethingChanged()
{
// this method is bound to an event somewhere
// call the parent class method, I don't care what type the parent
class is just that is has the MyCustomMethod() method.
if (this.Parent.GetType().GetMember("MyCustomMethod").GetLength(0) > 0)
this.parent.MyCustomMethod(this)
}
}
thanks for all the help
I need some help in understanding how to use Generics. I have a class
based on a user control that can be put on any Container at runtime, I
want to be able to call a method on the parent class without knowing the
type of the parent class, can this be done with C#?
I thought this was what Generics was supposed to be all about but I have
spent the whole day Googling and I can't find a way to do this in C#.
An example would be
public class MyClass : UserControl
{
public void SomethingChanged()
{
// this method is bound to an event somewhere
// call the parent class method, I don't care what type the parent
class is just that is has the MyCustomMethod() method.
if (this.Parent.GetType().GetMember("MyCustomMethod").GetLength(0) > 0)
this.parent.MyCustomMethod(this)
}
}
thanks for all the help