Пример #1
0
        protected virtual JsonContract CreateContract(Type objectType)
        {
            Type type = ReflectionUtils.EnsureNotNullableType(objectType);

            if (DefaultContractResolver.IsJsonPrimitiveType(objectType))
            {
                return(this.CreatePrimitiveContract(objectType));
            }
            if (JsonTypeReflector.GetJsonObjectAttribute(type) != null)
            {
                return(this.CreateObjectContract(objectType));
            }
            if (JsonTypeReflector.GetJsonArrayAttribute(type) != null)
            {
                return(this.CreateArrayContract(objectType));
            }
            if (JsonTypeReflector.GetJsonDictionaryAttribute(type) != null)
            {
                return(this.CreateDictionaryContract(objectType));
            }
            if (type == typeof(JToken) || type.IsSubclassOf(typeof(JToken)))
            {
                return(this.CreateLinqContract(objectType));
            }
            if (CollectionUtils.IsDictionaryType(type))
            {
                return(this.CreateDictionaryContract(objectType));
            }
            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                return(this.CreateArrayContract(objectType));
            }
            if (DefaultContractResolver.CanConvertToString(type))
            {
                return(this.CreateStringContract(objectType));
            }
            if (!this.IgnoreSerializableInterface && typeof(ISerializable).IsAssignableFrom(type))
            {
                return(this.CreateISerializableContract(objectType));
            }
            if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(type))
            {
                return(this.CreateDynamicContract(objectType));
            }
            if (DefaultContractResolver.IsIConvertible(type))
            {
                return(this.CreatePrimitiveContract(type));
            }
            return(this.CreateObjectContract(objectType));
        }