/// <summary> /// Creates an instance of an Immutable. /// </summary> public Immutable() { if (DelegateCache <T> .FactoryDelegate == null) { DelegateCache <T> .FactoryDelegate = DelegateBuilder.BuildFactory <T>(); } _self = DelegateCache <T> .FactoryDelegate(); }
/// <summary> /// Creates a new instance of an Immutable using a stuffed enclosed type. /// </summary> /// <param name="self">The instance to create the Immutable from.</param> /// <returns>A new Immutable with a cloned enclosed instance.</returns> public static Immutable <T> Create(T self) { if (DelegateCache <T> .CloneDelegate == null) { DelegateCache <T> .CloneDelegate = DelegateBuilder.BuildCloner <T>(); } if (DelegateCache <T> .FactoryDelegate == null) { DelegateCache <T> .FactoryDelegate = DelegateBuilder.BuildFactory <T>(); } return(new Immutable <T>(DelegateCache <T> .CloneDelegate(DelegateCache <T> .FactoryDelegate(), self))); }
/// <summary> /// Clones an enclosed immutable type. /// </summary> /// <returns>A copy of the enclosed type.</returns> private T Clone() { if (DelegateCache <T> .FactoryDelegate == null) { DelegateCache <T> .FactoryDelegate = DelegateBuilder.BuildFactory <T>(); } var newItem = DelegateCache <T> .FactoryDelegate(); if (DelegateCache <T> .CloneDelegate == null) { DelegateCache <T> .CloneDelegate = DelegateBuilder.BuildCloner <T>(); } return(DelegateCache <T> .CloneDelegate(newItem, _self)); }