IgnoreEmptyCollectionsContractResolver
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections;
using System.Reflection;
namespace NJsonSchema.Infrastructure
{
internal class IgnoreEmptyCollectionsContractResolver : PropertyRenameAndIgnoreSerializerContractResolver
{
protected override Newtonsoft.Json.Serialization.JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
Newtonsoft.Json.Serialization.JsonProperty property = base.CreateProperty(member, memberSerialization);
if ((property.Required == Required.Default || property.Required == Required.DisallowNull) && (object)property.PropertyType != typeof(string) && typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(property.PropertyType.GetTypeInfo()))
property.ShouldSerialize = ((object instance) => ((instance != null) ? (property.ValueProvider.GetValue(instance) as IEnumerable) : null)?.GetEnumerator().MoveNext() ?? true);
return property;
}
}
}