protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); if (property.Ignored) { return(property); } if (property.NullValueHandling != null) { if (TypeHelper.IsInterface(property.DeclaringType, typeof(ISynchronized))) { var propertyName = property.PropertyName; if (!TypeHelper.IsEnumerable(property.PropertyType)) { property.ShouldSerialize = instance => { var e = (ISynchronized)instance; return(e.Changes.ContainsKey(propertyName)); }; } else if (TypeHelper.IsInterface(TypeHelper.GetItemType(property.PropertyType), typeof(ISynchronized))) { var propertyInvoker = EmitInvoker.Initialize(property.DeclaringType, propertyName); property.ShouldSerialize = instance => { var collection = (IEnumerable)propertyInvoker.GetValue(instance); return(collection != null && collection.TypeOf <ISynchronized>().Any(p => p.SyncStatus != SynchronizedStatus.Actual)); }; } } } else if (member.GetCustomAttribute <JsonIgnoreSerializationAttribute>() != null) { property.ShouldSerialize = instance => false; } return(property); }
public static bool CheckItemT <T>(T x, object y, CompareType compare, IComparer <T> comparer) { bool result = false; switch (compare.Type) { case CompareTypes.Equal: result = EqualT(x, y == null ? default(T) : (T)y); break; case CompareTypes.Is: result = x == null; break; case CompareTypes.Like: y = (y?.ToString() ?? string.Empty).Trim(new char[] { '%' }); result = (x?.ToString() ?? string.Empty).IndexOf((string)y, 0, StringComparison.OrdinalIgnoreCase) >= 0; break; case CompareTypes.In: if (x is Enum && y is Enum) { result = ((int)y & (int)(object)x) != 0; //TODO Find the way to aviod BOXING ((int)y & (int)x) != 0; } else if (y is string yString) { result = yString.IndexOf(x?.ToString(), StringComparison.OrdinalIgnoreCase) >= 0; } else if (x != null && TypeHelper.IsEnumerable(x.GetType())) { result = x.ToEnumerable <T>().Intersect(y.ToEnumerable <T>()).Any(); } else { foreach (T item in y.ToEnumerable <T>()) { if (EqualT(x, item)) { result = true; break; } } } break; case CompareTypes.Contains: result = x.ToEnumerable().Contains(y); break; case CompareTypes.Intersect: result = x.ToEnumerable().Intersect(y.ToEnumerable()).Any(); break; default: int i = CompareT(x, y == null ? default(T) : (T)y, comparer); switch (compare.Type) { case CompareTypes.Greater: result = i > 0; break; case CompareTypes.Less: result = i < 0; break; case CompareTypes.GreaterOrEqual: result = i >= 0; break; case CompareTypes.LessOrEqual: result = i <= 0; break; } break; } return(compare.Not ? !result : result); }