/// <summary>
 /// Performs post-deserialization actions.
 /// </summary>
 /// <param name="sender"></param>
 public virtual void OnDeserialization(object sender)
 {
     if (provider == null || provider.GetType() == typeof(ArithmeticProvider))
     {
         provider = ArithmeticProvider.Default;
     }
     OverflowAllowed   = (Rules.OverflowBehavior == OverflowBehavior.AllowOverflow);
     NullIsZero        = (Rules.NullBehavior == NullBehavior.ThreatNullAsZero);
     cachedArithmetics = ThreadSafeDictionary <ArithmeticRules, Arithmetic <T> > .Create(new object());
 }
        // Constructors

        private LambdaExpressionFactory()
        {
            cache = ThreadSafeDictionary <Type, Factory> .Create(new object());

            factoryMethod = typeof(Expression).GetMethods()
                            .Where(m => m.IsGenericMethod &&
                                   m.Name == "Lambda" &&
                                   m.GetParameters()[1].ParameterType == typeof(IEnumerable <ParameterExpression>))
                            .Single();
        }
Exemple #3
0
        // Constructors

        private LambdaExpressionFactory()
        {
            cache = ThreadSafeDictionary <Type, Factory> .Create(new object());

            slowFactoryMethod = WellKnownTypes.Expression.GetMethods().Single(m =>
                                                                              m.IsGenericMethod &&
                                                                              m.Name == "Lambda" &&
                                                                              m.GetParameters()[1].ParameterType == typeof(IEnumerable <ParameterExpression>));

            createHandler = CanUseFastFactory() ? (Func <Type, Factory>)CreateFactoryFast : CreateFactorySlow;
        }
 /// <summary>
 /// Performs post-deserialization actions.
 /// </summary>
 /// <param name="sender"></param>
 public virtual void OnDeserialization(object sender)
 {
     if (provider == null)
     {
         provider = ComparerProvider.Default;
     }
     else if (provider.GetType() == typeof(ComparerProvider))
     {
         provider = ComparerProvider.Default;
     }
     else if (provider is SystemComparerProvider)
     {
         provider = ComparerProvider.System;
     }
     cachedComparers = ThreadSafeDictionary <ComparisonRules, AdvancedComparer <T> > .Create(new object());
 }
 private void Initialize()
 {
     results = ThreadSafeDictionary <Pair <Type>, int> .Create(new object());
 }
 /// <summary>
 /// Performs post-deserialization actions.
 /// </summary>
 /// <param name="sender"></param>
 public virtual void OnDeserialization(object sender)
 {
     _lock = new object();
     cache = ThreadSafeDictionary <TypePair, object> .Create(_lock);
 }
        // Constructors

        /// <summary>
        /// Initializes a new instance of this type.
        /// </summary>
        protected AssociateProvider()
        {
            constructorParams = new object[] { this };
            _lock             = new object();
            cache             = ThreadSafeDictionary <TypePair, object> .Create(_lock);
        }
        public void CombinedTest()
        {
            var dictionary = ThreadSafeDictionary <int, string> .Create(new object());

            // SetValue
            string one;

            Assert.IsFalse(
                dictionary.TryGetValue(1, out one));
            Assert.IsNull(one);

            dictionary.SetValue(1, "One");

            Assert.IsTrue(
                dictionary.TryGetValue(1, out one));

            Assert.AreEqual("One", one);

            // GetValue with generaors
            string two = dictionary.GetValue(2,
                                             delegate { return("Two"); });

            Assert.AreEqual("Two", two);

            bool twoRecalculated = false;

            two = dictionary.GetValue(2,
                                      delegate
            {
                twoRecalculated = true;
                return("Two");
            });

            Assert.AreEqual("Two", two);
            Assert.IsFalse(twoRecalculated);

            // Null value
            string zero = dictionary.GetValue(0,
                                              delegate { return(null); });

            Assert.AreEqual(null, zero);

            bool zeroRecalculated = false;

            zero = dictionary.GetValue(0,
                                       delegate
            {
                zeroRecalculated = true;
                return(null);
            });

            Assert.IsNull(zero);
            Assert.IsFalse(zeroRecalculated);


            var dictionary2 = ThreadSafeDictionary <int, int> .Create(new object());

            int i;

            dictionary2.TryGetValue(0, out i);
            Assert.AreEqual(0, i);
        }