/// <summary> /// Initializes a new instance of the <see cref="JsonObjectContract"/> class. /// </summary> /// <param name="underlyingType">The underlying type for the contract.</param> public JsonObjectContract(Type underlyingType) : base(underlyingType) { ContractType = JsonContractType.Object; Properties = new JsonPropertyCollection(UnderlyingType); ConstructorParameters = new JsonPropertyCollection(UnderlyingType); }
/// <summary> /// Initializes a new instance of the <see cref="JsonDynamicContract"/> class. /// </summary> /// <param name="underlyingType">The underlying type for the contract.</param> public JsonDynamicContract(Type underlyingType) : base(underlyingType) { ContractType = JsonContractType.Dynamic; Properties = new JsonPropertyCollection(UnderlyingType); ClearCacheEvent += OnClearCache; }
protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties) { ParameterInfo[] parameters = constructor.GetParameters(); JsonPropertyCollection propertys = new JsonPropertyCollection(constructor.DeclaringType); foreach (ParameterInfo info in parameters) { JsonProperty matchingMemberProperty = (info.Name != null) ? memberProperties.GetClosestMatchProperty(info.Name) : null; if ((matchingMemberProperty != null) && (matchingMemberProperty.PropertyType != info.ParameterType)) { matchingMemberProperty = null; } JsonProperty property = this.CreatePropertyFromConstructorParameter(matchingMemberProperty, info); if (property != null) { propertys.AddProperty(property); } } return(propertys); }
protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { List <MemberInfo> serializableMembers = this.GetSerializableMembers(type); if (serializableMembers == null) { throw new JsonSerializationException("Null collection of seralizable members returned."); } JsonPropertyCollection propertyCollection = new JsonPropertyCollection(type); foreach (MemberInfo member in serializableMembers) { JsonProperty property = this.CreateProperty(member, memberSerialization); if (property != null) { propertyCollection.AddProperty(property); } } return((IList <JsonProperty>)Enumerable.ToList <JsonProperty>((IEnumerable <JsonProperty>)Enumerable.OrderBy <JsonProperty, int>((IEnumerable <JsonProperty>)propertyCollection, (Func <JsonProperty, int>)(p => p.Order ?? -1)))); }
protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties) { ParameterInfo[] parameters = constructor.GetParameters(); JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(constructor.DeclaringType); foreach (ParameterInfo parameterInfo in parameters) { JsonProperty jsonProperty = memberProperties.GetClosestMatchProperty(parameterInfo.Name); if (jsonProperty != null && jsonProperty.PropertyType != parameterInfo.ParameterType) { jsonProperty = null; } JsonProperty jsonProperty2 = this.CreatePropertyFromConstructorParameter(jsonProperty, parameterInfo); if (jsonProperty2 != null) { jsonPropertyCollection.AddProperty(jsonProperty2); } } return(jsonPropertyCollection); }
protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { List <MemberInfo> serializableMembers = GetSerializableMembers(type); if (serializableMembers == null) { throw new JsonSerializationException("Null collection of seralizable members returned."); } JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(type); foreach (MemberInfo item in serializableMembers) { JsonProperty jsonProperty = CreateProperty(item, memberSerialization); if (jsonProperty != null) { jsonPropertyCollection.AddProperty(jsonProperty); } } return(jsonPropertyCollection.OrderBy((JsonProperty p) => p.Order ?? (-1)).ToList()); }
protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties) { ParameterInfo[] parameters = constructor.GetParameters(); JsonPropertyCollection propertyCollection = new JsonPropertyCollection(constructor.DeclaringType); foreach (ParameterInfo parameterInfo in parameters) { JsonProperty matchingMemberProperty = parameterInfo.Name != null?memberProperties.GetClosestMatchProperty(parameterInfo.Name) : (JsonProperty)null; if (matchingMemberProperty != null && matchingMemberProperty.PropertyType != parameterInfo.ParameterType) { matchingMemberProperty = (JsonProperty)null; } JsonProperty constructorParameter = this.CreatePropertyFromConstructorParameter(matchingMemberProperty, parameterInfo); if (constructorParameter != null) { propertyCollection.AddProperty(constructorParameter); } } return((IList <JsonProperty>)propertyCollection); }
protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties) { ParameterInfo[] parameters = constructor.GetParameters(); JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(constructor.DeclaringType); ParameterInfo[] parameterInfoArray = parameters; for (int i = 0; i < (int)parameterInfoArray.Length; i++) { ParameterInfo parameterInfo = parameterInfoArray[i]; JsonProperty closestMatchProperty = memberProperties.GetClosestMatchProperty(parameterInfo.Name); if (closestMatchProperty != null && closestMatchProperty.PropertyType != parameterInfo.ParameterType) { closestMatchProperty = null; } JsonProperty jsonProperty = this.CreatePropertyFromConstructorParameter(closestMatchProperty, parameterInfo); if (jsonProperty != null) { jsonPropertyCollection.AddProperty(jsonProperty); } } return(jsonPropertyCollection); }
/// <summary> /// Creates properties for the given <see cref="JsonContract"/>. /// </summary> /// <param name="type">The type to create properties for.</param> /// /// <param name="memberSerialization">The member serialization mode for the type.</param> /// <returns>Properties for the given <see cref="JsonContract"/>.</returns> protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { List <MemberInfo> members = GetSerializableMembers(type); if (members == null) { throw new JsonSerializationException("Null collection of seralizable members returned."); } JsonPropertyCollection properties = new JsonPropertyCollection(type); foreach (MemberInfo member in members) { JsonProperty property = CreateProperty(member, memberSerialization); if (property != null) { properties.AddProperty(property); } } return(properties); }
/// <summary> /// Creates properties for the given <see cref="JsonObjectContract"/>. /// </summary> /// <param name="contract">The contract to create properties for.</param> /// <returns>Properties for the given <see cref="JsonObjectContract"/>.</returns> protected virtual IList <JsonProperty> CreateProperties(JsonObjectContract contract) { List <MemberInfo> members = GetSerializableMembers(contract.UnderlyingType); if (members == null) { throw new JsonSerializationException("Null collection of seralizable members returned."); } JsonPropertyCollection properties = new JsonPropertyCollection(contract); foreach (MemberInfo member in members) { JsonProperty property = CreateProperty(contract, member); if (property != null) { properties.AddProperty(property); } } return(properties); }
protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { List <MemberInfo> serializableMembers = this.GetSerializableMembers(type); if (serializableMembers == null) { throw new JsonSerializationException("Null collection of seralizable members returned."); } JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(type); foreach (MemberInfo member in serializableMembers) { JsonProperty jsonProperty = this.CreateProperty(member, memberSerialization); if (jsonProperty != null) { jsonPropertyCollection.AddProperty(jsonProperty); } } return(jsonPropertyCollection.OrderBy(delegate(JsonProperty p) { int?order = p.Order; return (order == null) ? -1 : order.Value; }).ToList <JsonProperty>()); }
protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { List <MemberInfo> serializableMembers = this.GetSerializableMembers(type); if (serializableMembers == null) { throw new JsonSerializationException("Null collection of seralizable members returned."); } JsonPropertyCollection source = new JsonPropertyCollection(type); foreach (MemberInfo info in serializableMembers) { JsonProperty property = this.CreateProperty(info, memberSerialization); if (property != null) { source.AddProperty(property); } } if (func_3 == null) { func_3 = new Func <JsonProperty, int>(DefaultContractResolver.smethod_8); } return(source.OrderBy <JsonProperty, int>(func_3).ToList <JsonProperty>()); }
/// <summary> /// Initializes a new instance of the <see cref="JsonDynamicContract"/> class. /// </summary> /// <param name="underlyingType">The underlying type for the contract.</param> public JsonDynamicContract(Type underlyingType) : base(underlyingType) { Properties = new JsonPropertyCollection(UnderlyingType); }
/// <summary> /// Initializes a new instance of the <see cref="JsonObjectContract"/> class. /// </summary> /// <param name="underlyingType">The underlying type for the contract.</param> public JsonObjectContract(Type underlyingType) : base(underlyingType) { Properties = new JsonPropertyCollection(); }
/// <summary> /// Creates the constructor parameters. /// </summary> /// <param name="constructor">The constructor to create properties for.</param> /// <param name="memberProperties">The type's member properties.</param> /// <returns>Properties for the given <see cref="ConstructorInfo"/>.</returns> protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties) { var constructorParameters = constructor.GetParameters(); JsonPropertyCollection parameterCollection = new JsonPropertyCollection(constructor.DeclaringType); foreach (ParameterInfo parameterInfo in constructorParameters) { JsonProperty matchingMemberProperty = memberProperties.GetClosestMatchProperty(parameterInfo.Name); // type must match as well as name if (matchingMemberProperty != null && matchingMemberProperty.PropertyType != parameterInfo.ParameterType) { matchingMemberProperty = null; } JsonProperty property = CreatePropertyFromConstructorParameter(matchingMemberProperty, parameterInfo); if (property != null) { parameterCollection.AddProperty(property); } } return(parameterCollection); }
public JsonObjectContract(Type underlyingType) : base(underlyingType) { this.ContractType = JsonContractType.Object; this.Properties = new JsonPropertyCollection(base.UnderlyingType); }
public JsonObjectContract(Type underlyingType) : base(underlyingType) { this.Properties = new JsonPropertyCollection(base.UnderlyingType); this.ConstructorParameters = new JsonPropertyCollection(base.UnderlyingType); }
/// <summary> /// Initializes a new instance of the <see cref="JsonObjectContract"/> class. /// </summary> /// <param name="underlyingType">The underlying type for the contract.</param> public JsonObjectContract(Type underlyingType) : base(underlyingType) { Properties = new JsonPropertyCollection(this); CreatedType = underlyingType; }