Casting generic interfaces

Joined
Jan 10, 2007
Messages
43,898
Location
In The Machine
I was wondering if there is anyway to down cast a generic interface?

What I whant to do is something like this, I have an interface like this

interfaceMyInterface
{
** T GetValue ();
}



and in code I would like some generic code*to do something like this:

MyStringClass : MyInterface


MyStringClass sc = new MyStringClass () ;
...
...
if (sc is MyInterface)
{
** MyInterface*dc = (MyInterface )sc ;
***object o = dc.GetValue () ;
}


I'm pretty sure that I can't do this and it would be best to add a second non generic interface that does the cast for me.

Any comments?

Cheers,

Stephen.




More...

View All Our Microsoft Related Feeds
 
Back
Top