public void DummyMethod() { CompositeBuilderInfo <MyComposite> cbi = null; CompositeBuilder cb = null; { #region CompositeCreationCode6 // 'cbi' is of type CompositeBuilderInfo<MyComposite> MyComposite prototype = cbi.Prototype(); prototype.MyProperty = "InitialValue"; MyComposite instance = cbi.Instantiate(); // 'instance' and 'prototype' now reference to same object, // but setting instance.MyProperty to null will fail. #endregion } { #region CompositeCreationCode7 // 'cb' is of type CompositeBuilder MyComposite prototype = cb.Prototype <MyComposite>(); // Alternatively, prototype could be acquired this way: MyComposite prototype2 = (MyComposite)cb.PrototypeFor(typeof(MyComposite)); // 'prototype' and 'prototype2' reference to same object prototype.MyProperty = "InitialValue"; MyComposite instance = cb.Instantiate <MyComposite>(); // 'instance, 'prototype' and 'prototype2' all reference // to the same object. // Setting instance.MyProperty to null will fail. #endregion } }
/// <summary> /// Helper method to easily invoke <see cref="CompositeBuilder.PrototypeFor(Type)"/> method when type is known at compile-time. /// </summary> /// <typeparam name="TComposite">The type of the composite.</typeparam> /// <param name="builder">The <see cref="CompositeBuilder"/>.</param> /// <returns>The return value of <see cref="CompositeBuilder.PrototypeFor(Type)"/> casted to <typeparamref name="TComposite"/>.</returns> public static TComposite Prototype <TComposite>(this CompositeBuilder builder) { return((TComposite)builder.PrototypeFor(typeof(TComposite))); }