public interface INode { void Hello (T t); } public class Stack { public T TheData; public readonly Foo TheFoo; public Stack (T t) { this.TheData = t; this.TheFoo = new Foo (t); } public INode GetNode () { return new Node (this); } public Foo GetFoo (T t) { return new Foo (t); } public Bar GetBar (T t) { return new Bar (t); } protected class Node : INode { public readonly Stack Stack; public Node (Stack stack) { this.Stack = stack; } public void Hello (T t) { } } public class Foo { public readonly T Data; public Bar GetBar () { return new Bar (Data); } public Foo (T t) { this.Data = t; } } public class Bar { public readonly U Data; public Bar (U u) { this.Data = u; } public Foo GetFoo (Stack stack) { return stack.TheFoo; } public class Baz { public readonly V Data; public Foo GetFoo (Stack stack) { return new Foo (stack.TheData); } public Bar GetBar () { return new Bar (Data); } public Baz (V v) { this.Data = v; } } } public void Test () { Stack.Foo foo1 = GetFoo (TheData); Foo foo2 = GetFoo (TheData); Stack.Foo foo3 = new Stack.Foo (TheData); Stack.Foo foo4 = new Stack.Foo (3.14F); Foo foo5 = new Foo (3.14); } } class A { public class Test { public static Nested Foo () { return null; } public class Nested { } } } class X { public static int Main () { Stack stack = new Stack (1); INode node = stack.GetNode (); Stack.Foo foo = stack.GetFoo (7); Stack.Bar bar = stack.GetBar (8); A.Test.Nested v = A.Test.Foo (); return 0; } }