An interesting question over on SO relating to nested generic classes. Given
An interesting question over on SO relating to nested generic classes. Given
type
TClassC = class
private
type
TClassD = class
private
x: T;
end;
end;
and an instantiation
var
obj: TClassC.TClassD;
what type would you expect obj.x to be? Integer or string?
Have I missed anything in my answer? It feels like having got as far as generating a hint, there out to be some way of referring to the inner class generic type parameter.
https://stackoverflow.com/questions/47167043
https://stackoverflow.com/questions/47167043
type
TClassC
private
type
TClassD
private
x: T;
end;
end;
and an instantiation
var
obj: TClassC
what type would you expect obj.x to be? Integer or string?
Have I missed anything in my answer? It feels like having got as far as generating a hint, there out to be some way of referring to the inner class generic type parameter.
https://stackoverflow.com/questions/47167043
https://stackoverflow.com/questions/47167043
Stefan Glienke Are you sure it's a compiler error in C#? This compiles fine for me. x is (correctly) treated as a string. To me, this is correct behaviour and what is wrong with Delphi's implementation.
ReplyDeletenamespace ConsoleApp3
{
class Program
{
public class ClassC
{
public class ClassD
{
public T x { get; set; }
}
}
static void Main(string[] args)
{
var tmp = new ClassC.ClassD();
tmp.x = "1";
}
}
}
Jason Smart Could be I had CS0693 treated as error.
ReplyDeleteAn IDE plugin could promote the Hint to an Error. This would not be that difficult to write.
ReplyDelete