- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
class Program
{
class A
{
//-----------------------------------------------------------------------
public static A CurrentRoot;
public static Dictionary<object, A> RootMap = new Dictionary<object, A>();
public static object Lock = new object();
//-----------------------------------------------------------------------
public int Test;
public A()
{
lock (Lock)
{
CurrentRoot = this;
b = new B();
}
}
internal class B
{
public B() { RootMap.Add(this, CurrentRoot); }
public A root { get { return RootMap[this]; } }
~B() { RootMap.Remove(this); }
}
public B b;
}
static void Main(string[] args)
{
A a1 = new A(); a1.Test = 555;
A a2 = new A(); a2.Test = 888;
Console.WriteLine(a1.b.root.Test); Console.WriteLine(a1.Test);
Console.WriteLine(a2.b.root.Test); Console.WriteLine(a2.Test);
Console.WriteLine(a1.b.root.b.root.b.root.b.root.b.root.Test);
}