示例#1
0
        public void TestUpdateShouldSerializeMaybeProtectedField()
        {
            MaybeContractResolverWrapper testWrapper = new MaybeContractResolverWrapper();
            JsonProperty property = new JsonProperty
            {
                PropertyType = typeof(Maybe <float>),
                PropertyName = "Price"
            };

            FakeClass fc = new FakeClass
            {
                Name = "test"
            };

            Assert.IsNotNull(testWrapper.TestUpdateShouldSerialize(property));
            Assert.IsFalse(property.ShouldSerialize(fc));
        }
示例#2
0
        public void TestUpdateShouldSerializeMaybeField()
        {
            MaybeContractResolverWrapper testWrapper = new MaybeContractResolverWrapper();
            JsonProperty property = new JsonProperty
            {
                PropertyType = typeof(Maybe <string>),
                PropertyName = nameof(FakeClass.Name)
            };

            FakeClass fc = new FakeClass
            {
                Name = "test"
            };

            Assert.IsNotNull(testWrapper.TestUpdateShouldSerialize(property));
            Assert.IsTrue(property.ShouldSerialize(fc));
        }
        protected virtual void ConfigureProperty(JsonProperty property, IMemberConfiguration memberConfiguration)
        {
            var predicate = memberConfiguration.ShouldSerializePredicate;

            if (predicate != null) //Can be the function defined in this.CreateProperty (check NHibernate initialized property) or a custom one
            {
                if (property.ShouldSerialize != null)
                {
                    property.ShouldSerialize =
                        instance => property.ShouldSerialize(instance) && predicate(instance); //first check if property is initialized
                }
                else
                {
                    property.ShouldSerialize = predicate;
                }
            }
            var predicate2 = memberConfiguration.ShouldDeserializePredicate;

            if (predicate2 != null)
            {
                if (property.ShouldDeserialize != null)
                {
                    property.ShouldDeserialize =
                        instance => property.ShouldDeserialize(instance) && predicate2(instance);
                }
                else
                {
                    property.ShouldDeserialize = predicate2;
                }
            }
            property.DefaultValueHandling = memberConfiguration.DefaultValueHandling;
            property.DefaultValue         = memberConfiguration.DefaultValue;
            if (!string.IsNullOrEmpty(memberConfiguration.SerializedName))
            {
                property.PropertyName = memberConfiguration.SerializedName;
            }
            property.Converter     = memberConfiguration.Converter;
            property.Ignored       = memberConfiguration.Ignored.HasValue && memberConfiguration.Ignored.Value;
            property.Writable      = memberConfiguration.Writable ?? property.Writable;
            property.Readable      = memberConfiguration.Readable ?? property.Readable;
            property.ValueProvider = new BreezeValueProvider(property.ValueProvider, memberConfiguration);
            property.Order         = memberConfiguration.Order ?? property.Order;
        }
 private static bool ShouldSerialize(JsonProperty property, object instance)
 {
     return(property.ShouldSerialize == null ||
            property.ShouldSerialize(instance));
 }
        private bool ShouldSerialize(JsonWriter writer, JsonProperty property, object target)
        {
            if (property.ShouldSerialize == null)
                return true;

            bool shouldSerialize = property.ShouldSerialize(target);

            if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose)
                TraceWriter.Trace(TraceLevel.Verbose, JsonPosition.FormatMessage(null, writer.Path, "ShouldSerialize result for property '{0}' on {1}: {2}".FormatWith(CultureInfo.InvariantCulture, property.PropertyName, property.DeclaringType, shouldSerialize)), null);

            return shouldSerialize;
        }