Y
Yan Vinogradov
Hi,
Turns out it's possible to spoof another type with Object.GetType
method. If you do this:
namespace N {
class C {
public new Type GetType() {
return (String.Empty.GetType());
}
}
}
and then somewhere in the code you do:
C c = new C();
Console.WriteLine(c.GetType())
the output will be "System.String"
Apparently the way to make it work right is to upcast the reference to
Object:
C c = new C();
Console.WriteLine(((Object)c).GetType())
will yeild "N.C"
I'd appreciate your comments on that.
Yan
Turns out it's possible to spoof another type with Object.GetType
method. If you do this:
namespace N {
class C {
public new Type GetType() {
return (String.Empty.GetType());
}
}
}
and then somewhere in the code you do:
C c = new C();
Console.WriteLine(c.GetType())
the output will be "System.String"
Apparently the way to make it work right is to upcast the reference to
Object:
C c = new C();
Console.WriteLine(((Object)c).GetType())
will yeild "N.C"
I'd appreciate your comments on that.
Yan