コード例 #1
0
ファイル: Immutable`T.cs プロジェクト: kkolstad/Immutable.Net
        /// <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
ファイル: Immutable`T.cs プロジェクト: kkolstad/Immutable.Net
        /// <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)));
        }
コード例 #3
0
ファイル: Immutable`T.cs プロジェクト: kkolstad/Immutable.Net
        /// <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));
        }