Created
March 19, 2020 18:17
-
-
Save stevehansen/6d7719d14b6507906a5abf3b5ffbe493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Runtime.Serialization; | |
namespace Unitialized | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
var a = CreateA(); | |
Debug.Assert(a.B.C.A == a); | |
} | |
private static IA CreateA() | |
{ | |
var a = FormatterServices.GetUninitializedObject(typeof(A)); | |
var b = FormatterServices.GetUninitializedObject(typeof(B)); | |
var c = FormatterServices.GetUninitializedObject(typeof(C)); | |
typeof(A).GetConstructor(new[] { typeof(IB) }).Invoke(a, new object[] { b }); | |
typeof(B).GetConstructor(new[] { typeof(IC) }).Invoke(b, new object[] { c }); | |
typeof(C).GetConstructor(new[] { typeof(IA) }).Invoke(c, new object[] { a }); | |
return a as IA; | |
} | |
} | |
interface IA | |
{ | |
IB B { get; } | |
} | |
interface IB | |
{ | |
IC C { get; } | |
} | |
interface IC | |
{ | |
IA A { get; } | |
} | |
class A : IA | |
{ | |
public IB B { get; } | |
public A(IB b) | |
{ | |
B = b; | |
} | |
} | |
class B : IB | |
{ | |
public IC C { get; } | |
public B(IC c) | |
{ | |
C = c; | |
} | |
} | |
class C : IC | |
{ | |
public IA A { get; } | |
public C(IA a) | |
{ | |
A = a; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment