private void InitializeContract(JsonContract contract) { JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType); if (containerAttribute != null) { contract.IsReference = containerAttribute._isReference; } else { DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(contract.UnderlyingType); // doesn't have a null value if (dataContractAttribute != null && dataContractAttribute.IsReference) { contract.IsReference = true; } } contract.Converter = ResolveContractConverter(contract.UnderlyingType); // then see whether object is compadible with any of the built in converters contract.InternalConverter = JsonSerializer.GetMatchingConverter(BuiltInConverters, contract.UnderlyingType); if (ReflectionUtils.HasDefaultConstructor(contract.CreatedType, true) || contract.CreatedType.IsValueType) { contract.DefaultCreator = GetDefaultCreator(contract.CreatedType); contract.DefaultCreatorNonPublic = (!contract.CreatedType.IsValueType && ReflectionUtils.GetDefaultConstructor(contract.CreatedType) == null); } ResolveCallbackMethods(contract, contract.UnderlyingType); }
private void InitializeContract(JsonContract contract) { JsonContainerAttribute jsonContainerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType); if (jsonContainerAttribute != null) { contract.IsReference = jsonContainerAttribute._isReference; } else { DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(contract.UnderlyingType); if (dataContractAttribute != null && dataContractAttribute.IsReference) { contract.IsReference = new bool?(true); } } contract.Converter = this.ResolveContractConverter(contract.UnderlyingType); contract.InternalConverter = JsonSerializer.GetMatchingConverter(DefaultContractResolver.BuiltInConverters, contract.UnderlyingType); if (ReflectionUtils.HasDefaultConstructor(contract.CreatedType, true) || contract.CreatedType.IsValueType) { contract.DefaultCreator = this.GetDefaultCreator(contract.CreatedType); contract.DefaultCreatorNonPublic = (!contract.CreatedType.IsValueType && ReflectionUtils.GetDefaultConstructor(contract.CreatedType) == null); } this.ResolveCallbackMethods(contract, contract.UnderlyingType); }
private void InitializeContract(JsonContract contract) { JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType); if (containerAttribute != null) { contract.IsReference = containerAttribute._isReference; } #if !PocketPC && !SILVERLIGHT foreach (MethodInfo method in contract.UnderlyingType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { Type prevAttributeType = null; ParameterInfo[] parameters = method.GetParameters(); if (IsValidCallback(method, parameters, typeof(OnSerializingAttribute), contract.OnSerializing, ref prevAttributeType)) { contract.OnSerializing = method; } if (IsValidCallback(method, parameters, typeof(OnSerializedAttribute), contract.OnSerialized, ref prevAttributeType)) { contract.OnSerialized = method; } if (IsValidCallback(method, parameters, typeof(OnDeserializingAttribute), contract.OnDeserializing, ref prevAttributeType)) { contract.OnDeserializing = method; } if (IsValidCallback(method, parameters, typeof(OnDeserializedAttribute), contract.OnDeserialized, ref prevAttributeType)) { contract.OnDeserialized = method; } } #endif }
private void InitializeContract(JsonContract contract) { JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType); if (containerAttribute != null) { contract.IsReference = containerAttribute._isReference; } #if !PocketPC && !NET20 else { DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(contract.UnderlyingType); // doesn't have a null value if (dataContractAttribute != null && dataContractAttribute.IsReference) { contract.IsReference = true; } } #endif contract.DefaultContstructor = ReflectionUtils.GetDefaultConstructor(contract.CreatedType, false) ?? ReflectionUtils.GetDefaultConstructor(contract.CreatedType, true); foreach (MethodInfo method in contract.UnderlyingType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { Type prevAttributeType = null; ParameterInfo[] parameters = method.GetParameters(); #if !PocketPC && !SILVERLIGHT && !NET20 if (IsValidCallback(method, parameters, typeof(OnSerializingAttribute), contract.OnSerializing, ref prevAttributeType)) { contract.OnSerializing = method; } if (IsValidCallback(method, parameters, typeof(OnSerializedAttribute), contract.OnSerialized, ref prevAttributeType)) { contract.OnSerialized = method; } if (IsValidCallback(method, parameters, typeof(OnDeserializingAttribute), contract.OnDeserializing, ref prevAttributeType)) { contract.OnDeserializing = method; } if (IsValidCallback(method, parameters, typeof(OnDeserializedAttribute), contract.OnDeserialized, ref prevAttributeType)) { contract.OnDeserialized = method; } #endif if (IsValidCallback(method, parameters, typeof(OnErrorAttribute), contract.OnError, ref prevAttributeType)) { contract.OnError = method; } } }
internal JsonContainerContract(Type underlyingType) : base(underlyingType) { JsonContainerAttribute jsonContainerAttribute = JsonTypeReflector.GetJsonContainerAttribute(underlyingType); if (jsonContainerAttribute != null) { if (jsonContainerAttribute.ItemConverterType != null) { this.ItemConverter = JsonConverterAttribute.CreateJsonConverterInstance(jsonContainerAttribute.ItemConverterType); } this.ItemIsReference = jsonContainerAttribute._itemIsReference; this.ItemReferenceLoopHandling = jsonContainerAttribute._itemReferenceLoopHandling; this.ItemTypeNameHandling = jsonContainerAttribute._itemTypeNameHandling; } }
private void InitializeContract(JsonContract contract) { JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.NonNullableUnderlyingType); if (containerAttribute != null) { contract.IsReference = containerAttribute._isReference; } contract.Converter = this.ResolveContractConverter(contract.NonNullableUnderlyingType); contract.InternalConverter = JsonSerializer.GetMatchingConverter(DefaultContractResolver.BuiltInConverters, contract.NonNullableUnderlyingType); if (ReflectionUtils.HasDefaultConstructor(contract.CreatedType, true) || TypeExtensions.IsValueType(contract.CreatedType)) { contract.DefaultCreator = this.GetDefaultCreator(contract.CreatedType); contract.DefaultCreatorNonPublic = !TypeExtensions.IsValueType(contract.CreatedType) && ReflectionUtils.GetDefaultConstructor(contract.CreatedType) == null; } this.ResolveCallbackMethods(contract, contract.NonNullableUnderlyingType); }
private void InitializeContract(JsonContract contract) { JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType); if (containerAttribute != null) { contract.IsReference = containerAttribute._isReference; } #if !PocketPC && !NET20 else { DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(contract.UnderlyingType); // doesn't have a null value if (dataContractAttribute != null && dataContractAttribute.IsReference) { contract.IsReference = true; } } #endif contract.Converter = ResolveContractConverter(contract.UnderlyingType); // then see whether object is compadible with any of the built in converters contract.InternalConverter = JsonSerializer.GetMatchingConverter(BuiltInConverters, contract.UnderlyingType); if (ReflectionUtils.HasDefaultConstructor(contract.CreatedType, true) || contract.CreatedType.IsValueType) { contract.DefaultCreator = GetDefaultCreator(contract.CreatedType); contract.DefaultCreatorNonPublic = (!contract.CreatedType.IsValueType && ReflectionUtils.GetDefaultConstructor(contract.CreatedType) == null); } foreach (MethodInfo method in contract.UnderlyingType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { // compact framework errors when getting parameters for a generic method // lame, but generic methods should not be callbacks anyway if (method.ContainsGenericParameters) { continue; } Type prevAttributeType = null; ParameterInfo[] parameters = method.GetParameters(); #if !PocketPC if (IsValidCallback(method, parameters, typeof(OnSerializingAttribute), contract.OnSerializing, ref prevAttributeType)) { contract.OnSerializing = method; } if (IsValidCallback(method, parameters, typeof(OnSerializedAttribute), contract.OnSerialized, ref prevAttributeType)) { contract.OnSerialized = method; } if (IsValidCallback(method, parameters, typeof(OnDeserializingAttribute), contract.OnDeserializing, ref prevAttributeType)) { contract.OnDeserializing = method; } if (IsValidCallback(method, parameters, typeof(OnDeserializedAttribute), contract.OnDeserialized, ref prevAttributeType)) { contract.OnDeserialized = method; } #endif if (IsValidCallback(method, parameters, typeof(OnErrorAttribute), contract.OnError, ref prevAttributeType)) { contract.OnError = method; } } }
public static JsonArrayAttribute GetJsonArrayAttribute(Type type) { return(JsonTypeReflector.GetJsonContainerAttribute(type) as JsonArrayAttribute); }