/// <summary> /// Determines which contract type is created for the given type. /// </summary> /// <param name="objectType">Type of the object.</param> /// <returns>A <see cref="JsonContract"/> for the given type.</returns> protected virtual JsonContract CreateContract(Type objectType) { Type t = ReflectionUtils.EnsureNotNullableType(objectType); if (JsonConvert.IsJsonPrimitiveType(t)) { return(CreatePrimitiveContract(objectType)); } if (JsonTypeReflector.GetJsonObjectAttribute(t) != null) { return(CreateObjectContract(objectType)); } if (JsonTypeReflector.GetJsonArrayAttribute(t) != null) { return(CreateArrayContract(objectType)); } if (JsonTypeReflector.GetJsonDictionaryAttribute(t) != null) { return(CreateDictionaryContract(objectType)); } if (t == typeof(JToken) || t.IsSubclassOf(typeof(JToken))) { return(CreateLinqContract(objectType)); } if (CollectionUtils.IsDictionaryType(t)) { return(CreateDictionaryContract(objectType)); } if (typeof(IEnumerable).IsAssignableFrom(t)) { return(CreateArrayContract(objectType)); } if (CanConvertToString(t)) { return(CreateStringContract(objectType)); } #if !(SILVERLIGHT || NETFX_CORE || PORTABLE) if (!IgnoreSerializableInterface && typeof(ISerializable).IsAssignableFrom(t)) { return(CreateISerializableContract(objectType)); } #endif #if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE) if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(t)) { return(CreateDynamicContract(objectType)); } #endif return(CreateObjectContract(objectType)); }
/// <summary> /// Determines which contract type is created for the given type. /// </summary> /// <param name="objectType">Type of the object.</param> /// <returns>A <see cref="JsonContract"/> for the given type.</returns> protected virtual JsonContract CreateContract(Type objectType) { Type t = ReflectionUtils.EnsureNotNullableType(objectType); if (JsonConvert.IsJsonPrimitiveType(t)) { return(CreatePrimitiveContract(t)); } if (JsonTypeReflector.GetJsonObjectAttribute(t) != null) { return(CreateObjectContract(t)); } if (JsonTypeReflector.GetJsonArrayAttribute(t) != null) { return(CreateArrayContract(t)); } if (t.IsSubclassOf(typeof(JToken))) { return(CreateLinqContract(t)); } if (CollectionUtils.IsDictionaryType(t)) { return(CreateDictionaryContract(t)); } if (typeof(IEnumerable).IsAssignableFrom(t)) { return(CreateArrayContract(t)); } if (CanConvertToString(t)) { return(CreateStringContract(t)); } #if !SILVERLIGHT && !PocketPC if (typeof(ISerializable).IsAssignableFrom(t)) { return(CreateISerializableContract(t)); } #endif #if !(NET35 || NET20 || SILVERLIGHT) if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(t)) { return(CreateDynamicContract(t)); } #endif return(CreateObjectContract(t)); }
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)); }
/// <summary> /// Determines which contract type is created for the given type. /// </summary> /// <param name="objectType">Type of the object.</param> /// <returns>A <see cref="JsonContract"/> for the given type.</returns> protected virtual JsonContract CreateContract(Type objectType) { Type t = ReflectionUtils.EnsureNotNullableType(objectType); if (JsonConvert.IsJsonPrimitiveType(t)) { return(CreatePrimitiveContract(t)); } if (JsonTypeReflector.GetJsonObjectAttribute(t) != null) { return(CreateObjectContract(t)); } if (JsonTypeReflector.GetJsonArrayAttribute(t) != null) { return(CreateArrayContract(t)); } if (t == typeof(JToken) || t.IsSubclassOf(typeof(JToken))) { return(CreateLinqContract(t)); } if (CollectionUtils.IsDictionaryType(t)) { return(CreateDictionaryContract(t)); } if (typeof(IEnumerable).IsAssignableFrom(t)) { return(CreateArrayContract(t)); } if (CanConvertToString(t)) { return(CreateStringContract(t)); } #if !((UNITY_WINRT && !UNITY_EDITOR) || (UNITY_WP8 || UNITY_WP_8_1)) if (typeof(ISerializable).IsAssignableFrom(t)) { return(CreateISerializableContract(t)); } #endif return(CreateObjectContract(t)); }
/// <summary> /// Determines which contract type is created for the given type. /// </summary> /// <param name="objectType">Type of the object.</param> /// <returns>A <see cref="JsonContract"/> for the given type.</returns> protected virtual JsonContract CreateContract(Type objectType) { if (JsonConvert.IsJsonPrimitiveType(objectType)) { return(CreatePrimitiveContract(objectType)); } if (JsonTypeReflector.GetJsonObjectAttribute(objectType) != null) { return(CreateObjectContract(objectType)); } if (JsonTypeReflector.GetJsonArrayAttribute(objectType) != null) { return(CreateArrayContract(objectType)); } if (objectType.IsSubclassOf(typeof(JToken))) { return(CreateLinqContract(objectType)); } if (CollectionUtils.IsDictionaryType(objectType)) { return(CreateDictionaryContract(objectType)); } if (typeof(IEnumerable).IsAssignableFrom(objectType)) { return(CreateArrayContract(objectType)); } if (CanConvertToString(objectType)) { return(CreateStringContract(objectType)); } #if !SILVERLIGHT && !PocketPC if (typeof(ISerializable).IsAssignableFrom(objectType)) { return(CreateISerializableContract(objectType)); } #endif return(CreateObjectContract(objectType)); }
protected virtual JsonContract CreateContract(Type objectType) { Type type = ReflectionUtils.EnsureNotNullableType(objectType); if (JsonConvert.IsJsonPrimitiveType(type)) { return(CreatePrimitiveContract(type)); } if (JsonTypeReflector.GetJsonObjectAttribute(type) != null) { return(CreateObjectContract(type)); } if (JsonTypeReflector.GetJsonArrayAttribute(type) != null) { return(CreateArrayContract(type)); } if (type == typeof(JToken) || type.IsSubclassOf(typeof(JToken))) { return(CreateLinqContract(type)); } if (CollectionUtils.IsDictionaryType(type)) { return(CreateDictionaryContract(type)); } if (typeof(IEnumerable).IsAssignableFrom(type)) { return(CreateArrayContract(type)); } if (CanConvertToString(type)) { return(CreateStringContract(type)); } if (typeof(ISerializable).IsAssignableFrom(type)) { return(CreateISerializableContract(type)); } return(CreateObjectContract(type)); }