public virtual JsonContract ResolveContract(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            ResolverContractKey key   = new ResolverContractKey(GetType(), type);
            JsonContract        value = default(JsonContract);

            if (!(GetCache()?.TryGetValue(key, out value) ?? false))
            {
                value = CreateContract(type);
                lock (_typeContractCacheLock)
                {
                    Dictionary <ResolverContractKey, JsonContract> cache      = GetCache();
                    Dictionary <ResolverContractKey, JsonContract> dictionary = ((cache != null) ? new Dictionary <ResolverContractKey, JsonContract>(cache) : new Dictionary <ResolverContractKey, JsonContract>());
                    dictionary[key] = value;
                    UpdateCache(dictionary);
                }
            }
            return(value);
        }
Beispiel #2
0
        public virtual JsonContract ResolveContract(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            ResolverContractKey key = new ResolverContractKey(this.GetType(), type);
            Dictionary <ResolverContractKey, JsonContract> cache = this.GetCache();
            JsonContract contract;

            if (cache == null || !cache.TryGetValue(key, out contract))
            {
                contract = this.CreateContract(type);
                lock (DefaultContractResolver._typeContractCacheLock)
                {
                    Dictionary <ResolverContractKey, JsonContract> local_2_1 = this.GetCache();
                    Dictionary <ResolverContractKey, JsonContract> local_3   = local_2_1 != null ? new Dictionary <ResolverContractKey, JsonContract>((IDictionary <ResolverContractKey, JsonContract>)local_2_1) : new Dictionary <ResolverContractKey, JsonContract>();
                    local_3[key] = contract;
                    this.UpdateCache(local_3);
                }
            }
            return(contract);
        }
Beispiel #3
0
        public virtual JsonContract ResolveContract(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            ResolverContractKey key = new ResolverContractKey(base.GetType(), type);
            Dictionary <ResolverContractKey, JsonContract> cache = this.GetCache();
            JsonContract jsonContract;

            if (cache == null || !cache.TryGetValue(key, out jsonContract))
            {
                jsonContract = this.CreateContract(type);
                lock (DefaultContractResolver._typeContractCacheLock)
                {
                    cache = this.GetCache();
                    Dictionary <ResolverContractKey, JsonContract> dictionary = (cache != null) ? new Dictionary <ResolverContractKey, JsonContract>(cache) : new Dictionary <ResolverContractKey, JsonContract>();
                    dictionary[key] = jsonContract;
                    this.UpdateCache(dictionary);
                }
            }
            return(jsonContract);
        }
Beispiel #4
0
 public bool Equals(ResolverContractKey other)
 {
     return(this._resolverType == other._resolverType && this._contractType == other._contractType);
 }