Scenario is very rare, but quite simple: you define a generic class, then create a nested class which inherits from outer class and define a associative field (of self type) wit
This is not an answer!
There are many aspects of your question. A little one is: If a type contains (because of inheritance, not allowed otherwise) a nested type with the same name as the type itself, and if that name is used inside the type, what does the name refer to?
It's hard to express in words, but here's the example I have in mind:
namespace N
{
class Mammal
{
// contains nested type of an unfortunate name
internal interface Giraffe
{
}
}
class Giraffe : Mammal
{
Giraffe g; // what's the fully qualified name of the type of g?
}
}
Note: This is easy! No generics! No problem with a class inheriting its own containing class.
The question here is, what is the type of g
? Is it N.Giraffe
(a class), or is it N.Giraffe.Giraffe
(an interface)? The correct answer is the latter. Because to find a meaning for the name Giraffe
, one first searches the members of the current type (in this case one finds the interface). Only if no match is found there, one proceeds to the members of the current namespace (where the current type would be found).