J
joseph_gallagher
Hi,
I've been playing with generics and I was wondering if anyone could
tell me why the following doesnt work, and if there is another way to
do it
public class A<T> where T : B, new() {
public B Get() {
B b = new B();
b.X = this;
return b;
}
}
public class B {
public A<B> X { set { } }
}
basicaly class A<T> knows that T is inherited from type B, but type B
contains a property X of type A<B> and I'd like to be able to set this
property from class A<T>, which I would have though should work since
the compiler knows T is of type B, I cant even cast this to A<B> as a
workaround.
Any help appreciated
I've been playing with generics and I was wondering if anyone could
tell me why the following doesnt work, and if there is another way to
do it
public class A<T> where T : B, new() {
public B Get() {
B b = new B();
b.X = this;
return b;
}
}
public class B {
public A<B> X { set { } }
}
basicaly class A<T> knows that T is inherited from type B, but type B
contains a property X of type A<B> and I'd like to be able to set this
property from class A<T>, which I would have though should work since
the compiler knows T is of type B, I cant even cast this to A<B> as a
workaround.
Any help appreciated