private static bool RunLazyInitializer_ComplexVal() { TestHarness.TestLog("* RunLazyInitializer_ComplexVal()"); LIX empty = new LIX(); LIX template = new LIX(33); // // Complicated overloads (value types). // LIX a = default(LIX); bool ainit = false; object alock = null; LIX b = template; bool binit = true; object block = null; LIX c = default(LIX); bool cinit = false; object clock = null; LIX d = template; bool dinit = true; object dlock = null; // Activator.CreateInstance (uninitialized). if (!LazyInitializer.EnsureInitialized <LIX>(ref a, ref ainit, ref alock).Equals(empty)) { TestHarness.TestLog(" > EnsureInitialized(ref a) != empty"); return(false); } else if (!a.Equals(empty)) { TestHarness.TestLog(" > the value of a != empty (" + a + ") after a call to EnsureInitialized(ref a)"); return(false); } // Activator.CreateInstance (already initialized). if (!LazyInitializer.EnsureInitialized <LIX>(ref b, ref binit, ref block).Equals(template)) { TestHarness.TestLog(" > EnsureInitialized(ref b) != template -- already initialized, should have been unchanged"); return(false); } else if (!b.Equals(template)) { TestHarness.TestLog(" > the value of b != template (" + b + ") after a call to EnsureInitialized(ref b)"); return(false); } // Func based initialization (uninitialized). if (!LazyInitializer.EnsureInitialized <LIX>(ref c, ref cinit, ref clock, () => template).Equals(template)) { TestHarness.TestLog(" > EnsureInitialized(ref c, ...) != template"); return(false); } else if (!c.Equals(template)) { TestHarness.TestLog(" > the value of c != template (" + c + ") after a call to EnsureInitialized(ref c, ..)"); return(false); } // Func based initialization (already initialized). LIX template2 = new LIX(template.f * 2); if (!LazyInitializer.EnsureInitialized <LIX>(ref d, ref dinit, ref dlock, () => template2).Equals(template)) { TestHarness.TestLog(" > EnsureInitialized(ref c, ...) != template -- already initialized, should have been unchanged"); return(false); } else if (!d.Equals(template)) { TestHarness.TestLog(" > the value of d != template (" + d + ") after a call to EnsureInitialized(ref d, ..)"); return(false); } return(true); }