示例#1
0
        /// <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();
        }
示例#2
0
        /// <summary>
        /// Modifies and returns a copy of the modified Immutable.
        /// </summary>
        /// <typeparam name="TValue">The type of the value to set.</typeparam>
        /// <param name="assignment">An action that assigns a new value to the immutable.</param>
        /// <returns>A new modified Immutable instance.</returns>
        public Immutable<T> Modify(Action<T> assignment)
        {
            if (DelegateCache<T>.CloneDelegate == null)
            {
                DelegateCache<T>.CloneDelegate = DelegateBuilder.BuildCloner<T>();
            }

            var immutable = new Immutable<T>();
            immutable._self = DelegateCache<T>.CloneDelegate(immutable._self, _self);
            assignment(immutable._self);

            return immutable;
        }
示例#3
0
        /// <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)));
        }
示例#4
0
        /// <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));
        }