Browse Source

optimise IsEmptyArray (#272)

pull/274/head
Simon Cropp 6 years ago
committed by GitHub
parent
commit
4a71a911d4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Microsoft.Tye.Core/Serialization/OmitDefaultAndEmptyArrayObjectGraphVisitor.cs

8
src/Microsoft.Tye.Core/Serialization/OmitDefaultAndEmptyArrayObjectGraphVisitor.cs

@ -23,11 +23,9 @@ namespace Microsoft.Tye.Serialization
return type.GetTypeInfo().IsValueType ? Activator.CreateInstance(type) : null;
}
private static bool IsEmptyArray(Type type, object? value)
private static bool IsEmptyArray(object? value)
{
return value is object
&& value is ICollection
&& ((ICollection)value).Count == 0;
return value is ICollection collection && collection.Count == 0;
}
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
@ -39,7 +37,7 @@ namespace Microsoft.Tye.Serialization
: GetDefault(key.Type);
return !Equals(value.Value, defaultValue)
&& !IsEmptyArray(value.Type, value.Value)
&& !IsEmptyArray(value.Value)
&& base.EnterMapping(key, value, context);
}
}

Loading…
Cancel
Save