protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var properties = base.CreateProperties(type, memberSerialization); var updateableProperties = new List<JsonProperty>(); foreach (var property in properties) { foreach (var o in type .GetRuntimeProperty(property.PropertyName) .GetCustomAttributes(typeof(UpdateableAttribute), false)) { var a = (UpdateableAttribute)o; if (a.Updateable) { updateableProperties.Add(property); } } } var additionalUpdateableProperties = properties .Where(p => !type.GetRuntimeProperty(p.PropertyName).GetCustomAttributes(typeof(UpdateableAttribute), false).Any()) .ToList(); updateableProperties.AddRange(additionalUpdateableProperties); return updateableProperties; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); if (!member.DeclaringType.IsGenericType) return property; var declaringType = member.DeclaringType.GetGenericTypeDefinition(); if (declaringType == typeof(ListResponse<>)) { var type = member.ReflectedType.GenericTypeArguments[0]; var attr = type.GetCustomAttribute<RootPropertyNameAttribute>(true); property.PropertyName = attr.PluralName; } if (declaringType == typeof(ItemResponse<>)) { var type = member.ReflectedType.GenericTypeArguments[0]; var attr = type.GetCustomAttribute<RootPropertyNameAttribute>(true); property.PropertyName = attr.SingularName; } return property; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var properties = base.CreateProperties(type, memberSerialization); var photosProperty = properties.Single(x => x.UnderlyingName == "DrawingSession"); properties.Remove(photosProperty); return properties; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization); IList<JsonProperty> convertedProperties = new List<JsonProperty>(); foreach (var p in properties) { IDocumentPropertySetting documentProperty = null; db.SharedSetting.Collection.ChangeDocumentPropertyForType(type, p.UnderlyingName, x => documentProperty = x); if (documentProperty != null) { if (documentProperty.IgnoreProperty) continue; } p.PropertyName = db.SharedSetting.Collection.ResolvePropertyName(type, p.UnderlyingName); if (p.PropertyName == "_key" || p.PropertyName == "_id" || p.PropertyName == "_rev") p.NullValueHandling = NullValueHandling.Ignore; convertedProperties.Add(p); } return convertedProperties; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); Predicate<object> shouldSerialize = property.ShouldSerialize; property.ShouldSerialize = obj => (shouldSerialize == null || shouldSerialize(obj)) && !property.IsValueEmptyCollection(obj); return property; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { return base.CreateProperties(type, memberSerialization).Where((prop) => { return prop.PropertyName != "__interceptors" && prop.PropertyName != "__target"; }).ToList(); }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); if (_rootTypes.Contains(property.PropertyType)) { property.Converter = _referenceConverter; property.MemberConverter = _referenceConverter; } else { if (property.PropertyType.IsGenericType) { foreach (Type @interface in property.PropertyType.GetInterfaces()) { if (@interface.IsGenericType) { if (@interface.GetGenericTypeDefinition() == typeof(ICollection<>)) { if (_rootTypes.Contains(@interface.GetGenericArguments()[0])) { property.Ignored = true; } } } } } } return property; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); switch (_requestType) { case RequestType.Get: { if (property.AttributeProvider.GetAttributes(false).Any(w => ReferenceEquals(w.TypeId, typeof(GetColumnAttribute)))) { return property; } break; } case RequestType.Post: { if (property.AttributeProvider.GetAttributes(false).Any(w => ReferenceEquals(w.TypeId, typeof(PostColumnAttribute)))) { return property; } break; } case RequestType.Put: { if (property.AttributeProvider.GetAttributes(false).Any(w => ReferenceEquals(w.TypeId, typeof(PostColumnAttribute)))) { return property; } break; } } return null; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { IList<JsonProperty> objProperties = new List<JsonProperty>(); IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization); //objProperties = properties.Where(p => mPropertiesToSerialize.Contains(p.PropertyName)).ToList(); //foreach (var jProperty in properties) //{ // if (!jProperty.PropertyType.IsClass) // continue; // var nestedObjProperties = base.CreateProperties(jProperty.PropertyType, memberSerialization); // foreach (var nestedjProperty in nestedObjProperties) // { // if (objProperties.Any(nj => (nj.PropertyName == nestedjProperty.PropertyName))) // continue; // if (mPropertiesToSerialize.Contains(nestedjProperty.PropertyName)) // { // objProperties.Add(nestedjProperty); // } // } //} return objProperties; }
/// <summary> /// Creates a /// <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for the given /// <see cref="T:System.Reflection.MemberInfo" />. /// </summary> /// <param name="member">The member to create a <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for.</param> /// <param name="memberSerialization">The member's parent <see cref="T:Newtonsoft.Json.MemberSerialization" />.</param> /// <returns> /// A created <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for the given <see cref="T:System.Reflection.MemberInfo" />. /// </returns> protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { try { var property = base.CreateProperty(member, memberSerialization); if (!property.Writable) { var prop = member as PropertyInfo; if (prop != null) { var hasPrivateSetter = prop.GetSetMethod(true) != null; property.Writable = hasPrivateSetter; } } return property; } catch(Exception ex) { Log.Fatal(string.Format("SerializationContracts failed to create a required property for '{0}'!",member.Name)); Log.Fatal(string.Format("SerializationContracts failed with the following message: {0}", ex.Message)); Log.Fatal(string.Format("SerializationContract failures could be caused by corrupt save files.")); } return null; }
/// <summary> /// Creates a <see cref="T:Newtonsoft.Json.Serialization.JsonProperty"/> for the given <see cref="T:System.Reflection.MemberInfo"/>. /// </summary> /// <param name="memberSerialization">The member's parent <see cref="T:Newtonsoft.Json.MemberSerialization"/>.</param><param name="member">The member to create a <see cref="T:Newtonsoft.Json.Serialization.JsonProperty"/> for.</param> /// <returns> /// A created <see cref="T:Newtonsoft.Json.Serialization.JsonProperty"/> for the given <see cref="T:System.Reflection.MemberInfo"/>. /// </returns> protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var jsonProp = base.CreateProperty(member, memberSerialization); var sfAttrs = member.GetCustomAttributes(typeof(SalesForceAttribute), true); // if there are no attr then no need to process any further if (!sfAttrs.Any()) return jsonProp; var sfAttr = sfAttrs.FirstOrDefault() as SalesForceAttribute; // if there are no attr then no need to process any further if (sfAttr == null) { return jsonProp; } // if ignore then we should skip it and return null if (sfAttr.Ignore || (updateResolver && sfAttr.IgnoreUpdate)) { return null; } // if no fieldname then we use the default if (string.IsNullOrEmpty(sfAttr.FieldName)) { return jsonProp; } jsonProp.PropertyName = sfAttr.FieldName; return jsonProp; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); if (IsIgnored(property.DeclaringType, property.PropertyName)) property.ShouldSerialize = instance => false; return property; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var inheritedProperties = new List<JsonProperty>(); if (type.BaseType != null) { // recursively add properties from base types inheritedProperties.AddRange(CreateProperties(type.BaseType, memberSerialization)); } var jsonPropertiesFromFields = type .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Select(f => { var jsonProperty = CreateProperty(f, memberSerialization); jsonProperty.Writable = jsonProperty.Readable = true; return jsonProperty; }) .ToArray(); var jsonPropertiesToKeep = jsonPropertiesFromFields .Concat(inheritedProperties) .GroupBy(p => p.UnderlyingName) .Select(g => g.First()) //< only keep first occurrency for each underlying name - weeds out dupes .Where(g => !(g.DeclaringType == typeof(AggregateRoot) && g.PropertyType == typeof(IUnitOfWork))) //< skip unit of work property .ToList(); return jsonPropertiesToKeep; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty res = base.CreateProperty(member, memberSerialization); res.Required = Required.AllowNull; return res; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var properties = base.CreateProperties(type, memberSerialization); if (IgnoreList == null) throw new Exception("No ignore list supplied"); Type matchedType = null; if (IgnoreList.ContainsKey(type)) matchedType = type; else if (type.BaseType != null && IgnoreList.ContainsKey(type.BaseType)) matchedType = type.BaseType; if (matchedType != null) { var list = IgnoreList[matchedType]; foreach (var property in properties) { if (list.Contains(property.PropertyName)) { property.Ignored = true; } } } return properties; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { if (type == typeof(Vector2) || type == typeof(Vector3) || type == typeof(Vector4)) return base.CreateProperties(type, memberSerialization).Where(p => p.PropertyName.Length == 1).ToList(); else return base.CreateProperties(type, memberSerialization); }
protected override JsonProperty CreateProperty( MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); Predicate<object> shouldSerialize = property.ShouldSerialize; property.ShouldSerialize = obj => _includeProperty(property) && (shouldSerialize == null || shouldSerialize(obj)); return property; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); //Console.WriteLine("dont worry, im right here"); if (property.DeclaringType == typeof(System.Int32) && property.PropertyName == "ExitCode") { property.ShouldSerialize = instanceOfProblematic => false; }/* property.ShouldSerialize = instance => { try { PropertyInfo prop = (PropertyInfo)member; if (prop.CanRead) { prop.GetValue(instance, null); return true; } } catch { } return false; };*/ return property; }
/// <summary> /// Creates a <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for the given <see cref="T:System.Reflection.MemberInfo" />. /// </summary> /// <param name="member">The member to create a <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for.</param> /// <param name="memberSerialization">The member's parent <see cref="T:Newtonsoft.Json.MemberSerialization" />.</param> /// <returns> /// A created <see cref="T:Newtonsoft.Json.Serialization.JsonProperty" /> for the given <see cref="T:System.Reflection.MemberInfo" />. /// </returns> protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var jsonProperty = base.CreateProperty(member, memberSerialization); jsonProperty.ShouldSerialize = this.ShouldSerialize(jsonProperty); return jsonProperty; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { return base.CreateProperties(type, memberSerialization) .Where(p => !_excludedProperties.Contains(p.PropertyName)) .ToList(); }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); var isDefaultValueIgnored = ((property.DefaultValueHandling ?? DefaultValueHandling.Ignore) & DefaultValueHandling.Ignore) != 0; if (!isDefaultValueIgnored || typeof (string).IsAssignableFrom(property.PropertyType) || !typeof (IEnumerable).IsAssignableFrom(property.PropertyType)) { // The property should not be ignored, or is of the type String or is not of the type IEnumerable // Just return the property return property; } // This check return true if the collection contains items Predicate<object> newShouldSerialize = obj => { var collection = property.ValueProvider.GetValue(obj) as ICollection; return collection == null || collection.Count != 0; }; var oldShouldSerialize = property.ShouldSerialize; // The property should serialize if the original check (if any) and the new check both incicate the value should be serialized property.ShouldSerialize = oldShouldSerialize != null ? o => oldShouldSerialize(o) && newShouldSerialize(o) : newShouldSerialize; return property; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Select(p => CreateProperty(p, memberSerialization)) .ToList(); props.ForEach(p => { p.Writable = true; p.Readable = true; }); return props; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var res = base.CreateProperty(member, memberSerialization); res.PropertyName = ToCamelCase(res.PropertyName); res.UnderlyingName = ToCamelCase(res.UnderlyingName); return res; }
/// <inheritdoc/> protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); DoNotSerializeEmptyLists(property); return property; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var jsonProperties = base.CreateProperties(type, memberSerialization) .Where(property => property.DeclaringType != typeof (DomainEvent) && property.PropertyName != "Meta") .ToList(); return jsonProperties; }
#pragma warning disable 1591 // Xml Comments // Todo : figure out why Silverlight doesn't have this - vital for serialization #if(!SILVERLIGHT) protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var properties = base.CreateProperties(type, memberSerialization); if( _options != null ) return properties.Where(p => _options.ShouldSerializeProperty(type, p.PropertyName)).ToList(); return properties; }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); if (property.PropertyName == "Users") { property.ShouldSerialize = i => false; } return property; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization); if (type == typeof(Member)) { properties = properties.Where(p => !_MemberPropertiesToIgnore.Contains(p.PropertyName)).ToList(); } return properties; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var properties = base.CreateProperties(type, memberSerialization); // Filter properties properties = properties.Where(p => p.PropertyName != "createdAt" && p.PropertyName != "updatedAt").ToList(); return properties; }
/// <summary> /// Returns a list of json Properties, where /// * Base class properties appear before derived class properties /// * Enum values are serialized as strings /// </summary> protected override IList<JsonProperty> CreateProperties( Type type, MemberSerialization memberSerialization) { return base.CreateProperties(type, memberSerialization) ?.OrderBy(p => GetInheritanceHierarchy(p.DeclaringType).Count) ?.Select(CamelCaseEnumValues) ?.ToList(); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { return(base.CreateProperties(type, memberSerialization) .ToList() .FindAll(p => !lstExclude.Contains(p.PropertyName))); }
private void SetPropertySettingsFromAttributes(JsonProperty property, ICustomAttributeProvider attributeProvider, string name, Type declaringType, MemberSerialization memberSerialization, out bool allowNonPublicAccess, out bool hasExplicitAttribute) { hasExplicitAttribute = false; DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(declaringType); DataMemberAttribute dataMemberAttribute; if (dataContractAttribute != null && attributeProvider is MemberInfo) { dataMemberAttribute = JsonTypeReflector.GetDataMemberAttribute((MemberInfo)attributeProvider); } else { dataMemberAttribute = null; } JsonPropertyAttribute propertyAttribute = JsonTypeReflector.GetAttribute <JsonPropertyAttribute>(attributeProvider); if (propertyAttribute != null) { hasExplicitAttribute = true; } bool hasIgnoreAttribute = (JsonTypeReflector.GetAttribute <JsonIgnoreAttribute>(attributeProvider) != null); string mappedName; if (propertyAttribute != null && propertyAttribute.PropertyName != null) { mappedName = propertyAttribute.PropertyName; } else if (dataMemberAttribute != null && dataMemberAttribute.Name != null) { mappedName = dataMemberAttribute.Name; } else { mappedName = name; } property.PropertyName = ResolvePropertyName(mappedName); property.UnderlyingName = name; if (propertyAttribute != null) { property.Required = propertyAttribute.Required; property.Order = propertyAttribute._order; } else if (dataMemberAttribute != null) { property.Required = (dataMemberAttribute.IsRequired) ? Required.AllowNull : Required.Default; property.Order = (dataMemberAttribute.Order != -1) ? (int?)dataMemberAttribute.Order : null; } else { property.Required = Required.Default; } property.Ignored = (hasIgnoreAttribute || (memberSerialization == MemberSerialization.OptIn && propertyAttribute == null && dataMemberAttribute == null )); // resolve converter for property // the class type might have a converter but the property converter takes presidence property.Converter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); property.MemberConverter = JsonTypeReflector.GetJsonConverter(attributeProvider, property.PropertyType); DefaultValueAttribute defaultValueAttribute = JsonTypeReflector.GetAttribute <DefaultValueAttribute>(attributeProvider); property.DefaultValue = (defaultValueAttribute != null) ? defaultValueAttribute.Value : null; property.NullValueHandling = (propertyAttribute != null) ? propertyAttribute._nullValueHandling : null; property.DefaultValueHandling = (propertyAttribute != null) ? propertyAttribute._defaultValueHandling : null; property.ReferenceLoopHandling = (propertyAttribute != null) ? propertyAttribute._referenceLoopHandling : null; property.ObjectCreationHandling = (propertyAttribute != null) ? propertyAttribute._objectCreationHandling : null; property.TypeNameHandling = (propertyAttribute != null) ? propertyAttribute._typeNameHandling : null; property.IsReference = (propertyAttribute != null) ? propertyAttribute._isReference : null; allowNonPublicAccess = false; if ((DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic) { allowNonPublicAccess = true; } if (propertyAttribute != null) { allowNonPublicAccess = true; } if (dataMemberAttribute != null) { allowNonPublicAccess = true; hasExplicitAttribute = true; } }
private void method_11(JsonProperty jsonProperty_0, object object_1, string string_0, Type type_0, MemberSerialization memberSerialization_0, out bool bool_4) { DataMemberAttribute attribute2; string propertyName; DataContractAttribute attribute = Class139.smethod_5(type_0); MemberInfo info = object_1 as MemberInfo; if ((attribute != null) && (info != null)) { attribute2 = Class139.smethod_6(info); } else { attribute2 = null; } JsonPropertyAttribute attribute3 = Class139.smethod_17 <JsonPropertyAttribute>(object_1); if (attribute3 != null) { jsonProperty_0.HasMemberAttribute = true; } if ((attribute3 != null) && (attribute3.PropertyName != null)) { propertyName = attribute3.PropertyName; } else if ((attribute2 != null) && (attribute2.Name != null)) { propertyName = attribute2.Name; } else { propertyName = string_0; } jsonProperty_0.PropertyName = this.ResolvePropertyName(propertyName); jsonProperty_0.UnderlyingName = string_0; bool flag = false; if (attribute3 != null) { jsonProperty_0.nullable_0 = attribute3.nullable_7; jsonProperty_0.Order = attribute3.nullable_6; jsonProperty_0.DefaultValueHandling = attribute3.nullable_1; flag = true; } else if (attribute2 != null) { jsonProperty_0.nullable_0 = new Required?(attribute2.IsRequired ? Required.AllowNull : Required.Default); jsonProperty_0.Order = (attribute2.Order != -1) ? new int?(attribute2.Order) : null; jsonProperty_0.DefaultValueHandling = !attribute2.EmitDefaultValue ? ((DefaultValueHandling?)1) : null; flag = true; } bool flag2 = ((Class139.smethod_17 <JsonIgnoreAttribute>(object_1) != null) || (Class139.smethod_17 <JsonExtensionDataAttribute>(object_1) != null)) || (Class139.smethod_17 <NonSerializedAttribute>(object_1) != null); if (memberSerialization_0 != MemberSerialization.OptIn) { bool flag3 = false; flag3 = Class139.smethod_17 <IgnoreDataMemberAttribute>(object_1) != null; jsonProperty_0.Ignored = flag2 || flag3; } else { jsonProperty_0.Ignored = flag2 || !flag; } jsonProperty_0.Converter = Class139.smethod_10(object_1, jsonProperty_0.PropertyType); jsonProperty_0.MemberConverter = Class139.smethod_10(object_1, jsonProperty_0.PropertyType); DefaultValueAttribute attribute4 = Class139.smethod_17 <DefaultValueAttribute>(object_1); if (attribute4 != null) { jsonProperty_0.DefaultValue = attribute4.Value; } jsonProperty_0.NullValueHandling = (attribute3 != null) ? attribute3.nullable_0 : null; jsonProperty_0.ReferenceLoopHandling = (attribute3 != null) ? attribute3.nullable_2 : null; jsonProperty_0.ObjectCreationHandling = (attribute3 != null) ? attribute3.nullable_3 : null; jsonProperty_0.TypeNameHandling = (attribute3 != null) ? attribute3.nullable_4 : null; jsonProperty_0.IsReference = (attribute3 != null) ? attribute3.nullable_5 : null; jsonProperty_0.ItemIsReference = (attribute3 != null) ? attribute3.nullable_8 : null; jsonProperty_0.ItemConverter = ((attribute3 == null) || (attribute3.ItemConverterType == null)) ? null : JsonConverterAttribute.smethod_0(attribute3.ItemConverterType); jsonProperty_0.ItemReferenceLoopHandling = (attribute3 != null) ? attribute3.nullable_9 : null; jsonProperty_0.ItemTypeNameHandling = (attribute3 != null) ? attribute3.nullable_10 : null; bool_4 = false; if ((this.DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic) { bool_4 = true; } if (attribute3 != null) { bool_4 = true; } if (memberSerialization_0 == MemberSerialization.Fields) { bool_4 = true; } if (attribute2 != null) { bool_4 = true; jsonProperty_0.HasMemberAttribute = true; } }
protected override JsonProperty CreateProperty([NotNull] MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); property.ShouldSerialize = x => { var propertyInfo = (PropertyInfo)member; if (propertyInfo.GetSetMethod(nonPublic: true) == null) { return(false); } if (property.PropertyType == typeof(string)) { return(true); } if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { return(((IEnumerable)propertyInfo.GetValue(x)).GetEnumerator().MoveNext()); } if (x is SettingsClass && property.PropertyType == typeof(bool)) { var defaultTrueProperties = new[] { nameof(DataClass.ArgumentConstruction), nameof(DataClass.ExtensionMethods) }; if (defaultTrueProperties.Any(y => y.EqualsOrdinalIgnoreCase(property.PropertyName))) { return(false); } } return(true); }; return(property); }
protected override JsonProperty CreateProperty(System.Reflection.MemberInfo member, MemberSerialization memberSerialization) { var prop = base.CreateProperty(member, memberSerialization); if (!prop.Writable) { var property = member as System.Reflection.PropertyInfo; if (property != null) { var hasPrivateSetter = property.GetSetMethod(true) != null; prop.Writable = hasPrivateSetter; } } return(prop); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { IList <JsonProperty> properties = base.CreateProperties(type, memberSerialization); // S3 events use non-standard key formatting for request IDs and need to be mapped to the correct properties if (type.FullName.Equals("Amazon.S3.Util.S3EventNotification+ResponseElementsEntity", StringComparison.Ordinal)) { foreach (JsonProperty property in properties) { if (property.PropertyName.Equals("XAmzRequestId", StringComparison.Ordinal)) { property.PropertyName = "x-amz-request-id"; } else if (property.PropertyName.Equals("XAmzId2", StringComparison.Ordinal)) { property.PropertyName = "x-amz-id-2"; } } } else if (type.FullName.Equals("Amazon.Lambda.KinesisEvents.KinesisEvent+Record", StringComparison.Ordinal)) { foreach (JsonProperty property in properties) { if (property.PropertyName.Equals("Data", StringComparison.Ordinal)) { property.MemberConverter = new JsonToMemoryStreamDataConverter(); } else if (property.PropertyName.Equals("ApproximateArrivalTimestamp", StringComparison.Ordinal)) { property.MemberConverter = new JsonNumberToDateTimeDataConverter(); } } } else if (type.FullName.Equals("Amazon.DynamoDBv2.Model.StreamRecord", StringComparison.Ordinal)) { foreach (JsonProperty property in properties) { if (property.PropertyName.Equals("ApproximateCreationDateTime", StringComparison.Ordinal)) { property.MemberConverter = new JsonNumberToDateTimeDataConverter(); } } } else if (type.FullName.Equals("Amazon.DynamoDBv2.Model.AttributeValue", StringComparison.Ordinal)) { foreach (JsonProperty property in properties) { if (property.PropertyName.Equals("B", StringComparison.Ordinal)) { property.MemberConverter = new JsonToMemoryStreamDataConverter(); } else if (property.PropertyName.Equals("BS", StringComparison.Ordinal)) { property.MemberConverter = new JsonToMemoryStreamListDataConverter(); } } } else if (type.FullName.Equals("Amazon.Lambda.SQSEvents.SQSEvent+MessageAttribute", StringComparison.Ordinal)) { foreach (JsonProperty property in properties) { if (property.PropertyName.Equals("BinaryValue", StringComparison.Ordinal)) { property.MemberConverter = new JsonToMemoryStreamDataConverter(); } else if (property.PropertyName.Equals("BinaryListValues", StringComparison.Ordinal)) { property.MemberConverter = new JsonToMemoryStreamListDataConverter(); } } } else if (type.FullName.StartsWith("Amazon.Lambda.CloudWatchEvents.") && (type.GetTypeInfo().BaseType?.FullName?.StartsWith("Amazon.Lambda.CloudWatchEvents.CloudWatchEvent`", StringComparison.Ordinal) ?? false)) { foreach (JsonProperty property in properties) { if (property.PropertyName.Equals("DetailType", StringComparison.Ordinal)) { property.PropertyName = "detail-type"; } } } return(properties); }
protected override JsonProperty CreateProperty(System.Reflection.MemberInfo Member, MemberSerialization MemberSerialization) { JsonProperty Property = base.CreateProperty(Member, MemberSerialization); if (Avoid.Contains(Property.PropertyName)) { Property.ShouldSerialize = i => false; } return(Property); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var result = new List <JsonProperty>(fields.Length + properties.Length); for (int i = 0; i < fields.Length; i++) { var f = fields[i]; var attributes = f.GetCustomAttributes(); // Serialize non-public fields only with a proper attribute if (!f.IsPublic && !attributes.Any(x => x is SerializeAttribute)) { continue; } // Check if has attribute to skip serialization bool noSerialize = false; foreach (var attribute in attributes) { if (_attributesIgnoreList.Contains(attribute.GetType())) { noSerialize = true; break; } } if (noSerialize) { continue; } var jsonProperty = CreateProperty(f, memberSerialization); jsonProperty.Writable = true; jsonProperty.Readable = true; if (_flaxType.IsAssignableFrom(f.FieldType)) { jsonProperty.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; jsonProperty.Converter = JsonSerializer.ObjectConverter; } result.Add(jsonProperty); } for (int i = 0; i < properties.Length; i++) { var p = properties[i]; // Serialize only properties with read/write if (!(p.CanRead && p.CanWrite && p.GetIndexParameters().GetLength(0) == 0)) { continue; } var attributes = p.GetCustomAttributes(); // Serialize non-public properties only with a proper attribute if ((!p.GetMethod.IsPublic || !p.SetMethod.IsPublic) && !attributes.Any(x => x is SerializeAttribute)) { continue; } // Check if has attribute to skip serialization bool noSerialize = false; foreach (var attribute in attributes) { if (_attributesIgnoreList.Contains(attribute.GetType())) { noSerialize = true; break; } } if (noSerialize) { continue; } var jsonProperty = CreateProperty(p, memberSerialization); jsonProperty.Writable = true; jsonProperty.Readable = true; if (_flaxType.IsAssignableFrom(p.PropertyType)) { jsonProperty.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; jsonProperty.Converter = JsonSerializer.ObjectConverter; } result.Add(jsonProperty); } return(result); }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var jsonProp = base.CreateProperty(member, memberSerialization); void Skip() { jsonProp.ShouldSerialize = o => false; jsonProp.ShouldDeserialize = o => false; } void Allow() { jsonProp.ShouldSerialize = o => true; jsonProp.ShouldDeserialize = o => true; } if (member is FieldInfo field) { jsonProp.Readable = true; jsonProp.Writable = true; if (JsonBlueprints.IsBlacklisted(field)) { Skip(); return(null); } //BodyPartTypes used by EquipmentEntities are stored as longs with a LongAsEnumAttribute if (field.FieldType == typeof(long)) { var attribute = field.GetCustomAttribute <LongAsEnumAttribute>(); if (attribute != null) { jsonProp.ValueProvider = new LongAsEnumValueProvider(field, attribute.EnumType); jsonProp.PropertyType = attribute.EnumType; jsonProp.MemberConverter = stringEnumConverter; jsonProp.Converter = stringEnumConverter; } } //BlueprintSettingsRoot contains Action and Func fields if (field.FieldType == typeof(System.Action) || field.FieldType == typeof(System.Func <bool>)) { Skip(); return(null); } if (typeof(IEnumerable <BlueprintScriptableObject>).IsAssignableFrom(field.FieldType)) { //Needed to deserialize AbilityFocus.b689c0b78297dda40a6ae2ff3b8adb5c.json //Newtonsoft.Json.JsonSerializationException // Error converting value "Blueprint:fc4b01e4c4ebbb4448016c03df01902f:MandragoraSwarmDamageFeature" to type 'Kingmaker.Blueprints.BlueprintScriptableObject'.Path 'CustomParameterVariants[0]' //ArgumentException: Could not cast or convert from System.String to Kingmaker.Blueprints.BlueprintScriptableObject. jsonProp.ItemConverter = BlueprintAssetIdConverter; } if (typeof(BlueprintScriptableObject).IsAssignableFrom(field.FieldType)) { //MemberConverter required to deserialize see //https://stackoverflow.com/questions/24946362/custom-jsonconverter-is-ignored-for-deserialization-when-using-custom-contract-r //jsonProp.MemberConverter = BlueprintAssetIdConverter; //jsonProp.Converter = BlueprintAssetIdConverter; //Allow(); } } else if (member is PropertyInfo property) { } else { throw new NotImplementedException($"Member type {member.MemberType} not implemented"); } return(jsonProp); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { return(base.CreateProperties(type, memberSerialization) .Where(p => IsPropertyUpdateable(type, p)) .ToList()); }
/// <summary> /// Initializes a new instance of the <see cref="JsonObjectAttribute"/> class with the specified member serialization. /// </summary> /// <param name="memberSerialization">The member serialization.</param> public JsonObjectAttribute(MemberSerialization memberSerialization) { MemberSerialization = memberSerialization; }
/// <inheritdoc /> protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { IList <JsonProperty> props = base.CreateProperties(type, memberSerialization); return(props.Where(p => p.PropertyType == typeof(ReadOnlyDictionary <string, DataModel>) || !p.AttributeProvider.GetAttributes(typeof(DataModelIgnoreAttribute), true).Any()).ToList()); }
protected override IList <Newtonsoft.Json.Serialization.JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var properties = base.CreateProperties(type, memberSerialization); foreach (var p in properties) { p.Ignored = false; } return(properties); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { IList <JsonProperty> props = base.CreateProperties(type, memberSerialization); return(props.Where(p => p.Writable).ToList()); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { IList <JsonProperty> baseProperties = base.CreateProperties(type, memberSerialization); return(baseProperties.Where(x => ShouldSerialize(x)).ToList()); }
/// <summary> /// Creates a <see cref="JsonProperty"/> for the given <see cref="MemberInfo"/>. /// </summary> /// <param name="memberSerialization">The member's parent <see cref="MemberSerialization"/>.</param> /// <param name="member">The member to create a <see cref="JsonProperty"/> for.</param> /// <returns>A created <see cref="JsonProperty"/> for the given <see cref="MemberInfo"/>.</returns> protected virtual JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = new JsonProperty(); property.PropertyType = ReflectionUtils.GetMemberUnderlyingType(member); property.ValueProvider = CreateMemberValueProvider(member); // resolve converter for property // the class type might have a converter but the property converter takes presidence property.Converter = JsonTypeReflector.GetJsonConverter(member, property.PropertyType); #if !PocketPC && !NET20 DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(member.DeclaringType); DataMemberAttribute dataMemberAttribute; if (dataContractAttribute != null) { dataMemberAttribute = JsonTypeReflector.GetAttribute <DataMemberAttribute>(member); } else { dataMemberAttribute = null; } #endif JsonPropertyAttribute propertyAttribute = JsonTypeReflector.GetAttribute <JsonPropertyAttribute>(member); bool hasIgnoreAttribute = (JsonTypeReflector.GetAttribute <JsonIgnoreAttribute>(member) != null); string mappedName; if (propertyAttribute != null && propertyAttribute.PropertyName != null) { mappedName = propertyAttribute.PropertyName; } #if !PocketPC && !NET20 else if (dataMemberAttribute != null && dataMemberAttribute.Name != null) { mappedName = dataMemberAttribute.Name; } #endif else { mappedName = member.Name; } property.PropertyName = ResolvePropertyName(mappedName); if (propertyAttribute != null) { property.Required = propertyAttribute.Required; } #if !PocketPC && !NET20 else if (dataMemberAttribute != null) { property.Required = (dataMemberAttribute.IsRequired) ? Required.AllowNull : Required.Default; } #endif else { property.Required = Required.Default; } property.Ignored = (hasIgnoreAttribute || (memberSerialization == MemberSerialization.OptIn && propertyAttribute == null #if !PocketPC && !NET20 && dataMemberAttribute == null #endif )); bool allowNonPublicAccess = false; if ((DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic) { allowNonPublicAccess = true; } if (propertyAttribute != null) { allowNonPublicAccess = true; } #if !PocketPC && !NET20 if (dataMemberAttribute != null) { allowNonPublicAccess = true; } #endif property.Readable = ReflectionUtils.CanReadMemberValue(member, allowNonPublicAccess); property.Writable = ReflectionUtils.CanSetMemberValue(member, allowNonPublicAccess); property.MemberConverter = JsonTypeReflector.GetJsonConverter(member, ReflectionUtils.GetMemberUnderlyingType(member)); DefaultValueAttribute defaultValueAttribute = JsonTypeReflector.GetAttribute <DefaultValueAttribute>(member); property.DefaultValue = (defaultValueAttribute != null) ? defaultValueAttribute.Value : null; property.NullValueHandling = (propertyAttribute != null) ? propertyAttribute._nullValueHandling : null; property.DefaultValueHandling = (propertyAttribute != null) ? propertyAttribute._defaultValueHandling : null; property.ReferenceLoopHandling = (propertyAttribute != null) ? propertyAttribute._referenceLoopHandling : null; property.ObjectCreationHandling = (propertyAttribute != null) ? propertyAttribute._objectCreationHandling : null; property.TypeNameHandling = (propertyAttribute != null) ? propertyAttribute._typeNameHandling : null; property.IsReference = (propertyAttribute != null) ? propertyAttribute._isReference : null; property.ShouldSerialize = CreateShouldSerializeTest(member); SetIsSpecifiedActions(property, member); return(property); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { #if !NETFX_CORE if (!type.IsClass || type == typeof(object) || typeof(Response).IsAssignableFrom(type) || typeof(IResponseRow).IsAssignableFrom(type)) { return(base.CreateProperties(type, memberSerialization)); } #else if (type == typeof(object)) { return(base.CreateProperties(type, memberSerialization)); } var typeInfo = type.GetTypeInfo(); if (!typeInfo.IsClass || ResponseTypeInfo.IsAssignableFrom(typeInfo) || ResponseRowTypeInfo.IsAssignableFrom(typeInfo)) { return(base.CreateProperties(type, memberSerialization)); } #endif var props = base.CreateProperties(type, memberSerialization); if (!props.Any()) { return(props); } int? idRank = null, revRank = null; JsonProperty id = null, rev = null; foreach (var prop in props) { var tmpRank = EntityReflector.IdMember.GetMemberRankingIndex(type, prop.PropertyName); if (tmpRank != null) { if (idRank == null || tmpRank < idRank) { idRank = tmpRank; id = prop; } continue; } tmpRank = EntityReflector.RevMember.GetMemberRankingIndex(type, prop.PropertyName); if (tmpRank != null) { if (revRank == null || tmpRank < revRank) { revRank = tmpRank; rev = prop; } } } if (id != null) { id.PropertyName = "_id"; } if (rev != null) { rev.PropertyName = "_rev"; } return(props); }
protected override IList <JsonProperty> CreateProperties([CanBeNull] Type type, MemberSerialization memberSerialization) { return(base.CreateProperties(type, MemberSerialization.Fields)); }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); if (member.GetCustomAttributes <OptionalAttribute>().Any() || property.DeclaringType.Name.EndsWith("Capabilities") ) { property.NullValueHandling = NullValueHandling.Ignore; } if (typeof(ISupports).IsAssignableFrom(property.PropertyType)) { property.ValueProvider = new SupportsValueProvider(property.ValueProvider); } if (property.DeclaringType == typeof(CompletionItem)) { if (property.PropertyType == typeof(CompletionItemKind)) { property.ValueProvider = new RangeValueProvider <CompletionItemKind>(property.ValueProvider, _completionItemKinds); } if (property.PropertyType == typeof(Container <CompletionItemTag>)) { property.ValueProvider = new ArrayRangeValueProvider <CompletionItemTag>(property.ValueProvider, _completionItemTags); } } if (property.DeclaringType == typeof(DocumentSymbol)) { if (property.PropertyType == typeof(SymbolKind)) { property.ValueProvider = new RangeValueProvider <SymbolKind>(property.ValueProvider, _documentSymbolKinds); } if (property.PropertyType == typeof(Container <SymbolTag>)) { property.ValueProvider = new ArrayRangeValueProvider <SymbolTag>(property.ValueProvider, _documentSymbolTags); } } if (property.DeclaringType == typeof(Diagnostic)) { if (property.PropertyType == typeof(Container <DiagnosticTag>)) { property.ValueProvider = new ArrayRangeValueProvider <DiagnosticTag>(property.ValueProvider, _diagnosticTags); } } if (property.DeclaringType == typeof(CodeAction)) { if (property.PropertyType == typeof(CodeActionKind)) { property.ValueProvider = new RangeValueProvider <CodeActionKind>(property.ValueProvider, _codeActionKinds); } } if (property.DeclaringType == typeof(SymbolInformation)) { if (property.PropertyType == typeof(SymbolKind)) { property.ValueProvider = new RangeValueProvider <SymbolKind>(property.ValueProvider, _workspaceSymbolKinds); } if (property.PropertyType == typeof(Container <SymbolTag>)) { property.ValueProvider = new ArrayRangeValueProvider <SymbolTag>(property.ValueProvider, _workspaceSymbolTags); } } return(property); }
protected override System.Collections.Generic.IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var list = base.CreateProperties(type, memberSerialization); foreach (var eventInfo in type.GetEvents(BindingFlags.Instance | BindingFlags.Public)) { var prop = CreateProperty(eventInfo, memberSerialization); prop.Writable = true; list.Add(prop); } var idprop = type.GetProperty("ID", BindingFlags.Instance | BindingFlags.Public); if (idprop != null) { var prop = CreateProperty(idprop, memberSerialization); prop.PropertyName = "$name"; prop.PropertyType = typeof(NameConverter.Info); prop.MemberConverter = new NameConverter(); prop.ValueProvider = new NameConverter.ValueProvider(); list.Add(prop); } return(list); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var list = base.CreateProperties(type, memberSerialization); return(list.Where(elem => elem.Readable && elem.Writable).ToList()); }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); if (property.DeclaringType == typeof(VersionOptions) && member.Name == nameof(VersionOptions.Schema)) { property.ShouldSerialize = instance => this.IncludeSchemaProperty; } if (!this.IncludeDefaults) { if (property.DeclaringType == typeof(VersionOptions) && member.Name == nameof(VersionOptions.AssemblyVersion)) { property.ShouldSerialize = instance => !((VersionOptions)instance).AssemblyVersionOrDefault.IsDefault; } if (property.DeclaringType == typeof(VersionOptions) && member.Name == nameof(VersionOptions.BuildNumberOffset)) { property.ShouldSerialize = instance => ((VersionOptions)instance).BuildNumberOffsetOrDefault != 0; } if (property.DeclaringType == typeof(VersionOptions) && member.Name == nameof(VersionOptions.NuGetPackageVersion)) { property.ShouldSerialize = instance => !((VersionOptions)instance).NuGetPackageVersionOrDefault.IsDefault; } if (property.DeclaringType == typeof(VersionOptions) && member.Name == nameof(VersionOptions.CloudBuild)) { property.ShouldSerialize = instance => !((VersionOptions)instance).CloudBuildOrDefault.IsDefault; } if (property.DeclaringType == typeof(VersionOptions.CloudBuildOptions) && member.Name == nameof(VersionOptions.CloudBuildOptions.SetAllVariables)) { property.ShouldSerialize = instance => ((VersionOptions.CloudBuildOptions)instance).SetAllVariablesOrDefault != VersionOptions.CloudBuildOptions.DefaultInstance.SetAllVariables.Value; } if (property.DeclaringType == typeof(VersionOptions.CloudBuildOptions) && member.Name == nameof(VersionOptions.CloudBuildOptions.SetVersionVariables)) { property.ShouldSerialize = instance => ((VersionOptions.CloudBuildOptions)instance).SetVersionVariablesOrDefault != VersionOptions.CloudBuildOptions.DefaultInstance.SetVersionVariables.Value; } if (property.DeclaringType == typeof(VersionOptions.CloudBuildNumberOptions) && member.Name == nameof(VersionOptions.CloudBuildNumberOptions.IncludeCommitId)) { property.ShouldSerialize = instance => !((VersionOptions.CloudBuildNumberOptions)instance).IncludeCommitIdOrDefault.IsDefault; } if (property.DeclaringType == typeof(VersionOptions.CloudBuildNumberCommitIdOptions) && member.Name == nameof(VersionOptions.CloudBuildNumberCommitIdOptions.When)) { property.ShouldSerialize = instance => ((VersionOptions.CloudBuildNumberCommitIdOptions)instance).WhenOrDefault != VersionOptions.CloudBuildNumberCommitIdOptions.DefaultInstance.When.Value; } if (property.DeclaringType == typeof(VersionOptions.CloudBuildNumberCommitIdOptions) && member.Name == nameof(VersionOptions.CloudBuildNumberCommitIdOptions.Where)) { property.ShouldSerialize = instance => ((VersionOptions.CloudBuildNumberCommitIdOptions)instance).WhereOrDefault != VersionOptions.CloudBuildNumberCommitIdOptions.DefaultInstance.Where.Value; } if (property.DeclaringType == typeof(VersionOptions) && member.Name == nameof(VersionOptions.Release)) { property.ShouldSerialize = instance => !((VersionOptions)instance).ReleaseOrDefault.IsDefault; } if (property.DeclaringType == typeof(VersionOptions.ReleaseOptions) && member.Name == nameof(VersionOptions.ReleaseOptions.BranchName)) { property.ShouldSerialize = instance => ((VersionOptions.ReleaseOptions)instance).BranchNameOrDefault != VersionOptions.ReleaseOptions.DefaultInstance.BranchName; } if (property.DeclaringType == typeof(VersionOptions.ReleaseOptions) && member.Name == nameof(VersionOptions.ReleaseOptions.VersionIncrement)) { property.ShouldSerialize = instance => ((VersionOptions.ReleaseOptions)instance).VersionIncrementOrDefault != VersionOptions.ReleaseOptions.DefaultInstance.VersionIncrement.Value; } if (property.DeclaringType == typeof(VersionOptions.ReleaseOptions) && member.Name == nameof(VersionOptions.ReleaseOptions.FirstUnstableTag)) { property.ShouldSerialize = instance => ((VersionOptions.ReleaseOptions)instance).FirstUnstableTagOrDefault != VersionOptions.ReleaseOptions.DefaultInstance.FirstUnstableTag; } } return(property); }
protected override System.Collections.Generic.IList <JsonProperty> CreateProperties(System.Type type, MemberSerialization memberSerialization) { return(base.CreateProperties(type, memberSerialization).OrderBy(p => p.PropertyName).ToList()); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var properties = base.CreateProperties(type, memberSerialization); return(properties.Where(p => (p.DeclaringType == type || p.DeclaringType == typeof(TimedExplosive) || p.DeclaringType == typeof(BaseMelee)) && IsAllowed(p)).ToList()); }
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { var property = base.CreateProperty(member, memberSerialization); #if NET45 //IgnoreNull标注的字段根据IgnoreNulls设定是否序列化 var ignoreNull = member.GetCustomAttribute <JsonSetting.IgnoreNullAttribute>(); if (ignoreNull != null || IgnoreNulls) { property.NullValueHandling = NullValueHandling.Ignore; } else { property.NullValueHandling = NullValueHandling.Include; } //propertiesToIgnoreNull指定字段为Null时不序列化 if (PropertiesToIgnoreNull.Contains(member.Name)) { property.NullValueHandling = NullValueHandling.Ignore; } ////符合IgnoreValue标注值的字段不序列化 //var ignoreValue = member.GetCustomAttribute<JsonSetting.IgnoreValueAttribute>(); //if (ignoreValue != null) //{ // property.DefaultValueHandling = DefaultValueHandling.Ignore; // var t = member.DeclaringType; // property.ShouldSerialize = instance => // { // var obj = Convert.ChangeType(instance, t); // var value = (member as PropertyInfo).GetValue(obj, null); // return value != ignoreValue.Value; // }; //} //枚举序列化 var enumString = member.GetCustomAttribute <JsonSetting.EnumStringAttribute>(); if (enumString != null) { property.Converter = new StringEnumConverter(); //property = base.CreateProperty(member, memberSerialization); } #else var customAttributes = member.GetCustomAttributes(false); var ignoreNullAttribute = typeof(JsonSetting.IgnoreNullAttribute); //IgnoreNull标注的字段根据IgnoreNulls设定是否序列化 if (IgnoreNulls || customAttributes.Count(o => o.GetType() == ignoreNullAttribute) == 1) { property.NullValueHandling = NullValueHandling.Ignore; } else { property.NullValueHandling = NullValueHandling.Include; } //propertiesToIgnoreNull指定字段为Null时不序列化 if (PropertiesToIgnoreNull.Contains(member.Name)) { property.NullValueHandling = NullValueHandling.Ignore; } ////符合IgnoreValue标注值的字段不序列化 //var ignoreValueAttribute = typeof(JsonSetting.IgnoreValueAttribute); //var ignoreValue = customAttributes.FirstOrDefault(o => o.GetType() == ignoreValueAttribute); //if (ignoreValue != null) //{ // property.DefaultValueHandling = DefaultValueHandling.Ignore; // var t = member.DeclaringType; // property.ShouldSerialize = instance => // { // var obj = Convert.ChangeType(instance, t); // var value = (member as PropertyInfo).GetValue(obj, null); // return value != (ignoreValue as JsonSetting.IgnoreValueAttribute).Value; // }; //} //枚举序列化 var enumStringAttribute = typeof(JsonSetting.EnumStringAttribute); if (customAttributes.Count(o => o.GetType() == enumStringAttribute) == 1) { property.Converter = new StringEnumConverter(); } #endif //var defaultIgnore = member.GetCustomAttribute<DefaultIgnoreAttribute>(); //if (defaultIgnore != null) //{ // //defaultIgnore.Value == member. //} return(property); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { return(base.CreateProperties(type, memberSerialization). OrderBy(p => p.DeclaringType.BaseTypesAndSelf().Count()). ToList()); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var props = base.CreateProperties(type, memberSerialization); return(props.Where(p => p.PropertyName != "Password").ToList()); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var allProps = base.CreateProperties(type, memberSerialization); return(allProps.Where(p => TypeDescriptor.GetConverter(p.PropertyType).CanConvertFrom(typeof(string))).ToList()); }
/// <summary> /// JsonPropertyOrder(alphabetic = true) /// </summary> protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { return(base.CreateProperties(type, memberSerialization).OrderBy(p => p.PropertyName).ToList()); }
protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) => filters .Where(filter => filter != null) .Aggregate( base.CreateProperties(type, memberSerialization), (acc, propertiesFilter) => propertiesFilter.Filter(acc));