예제 #1
0
        public void WriteJsonProperty(JsonWriter writer, JsonSerializer serializer, ModifiableEntity mod, string lowerCaseName, PropertyConverter pc, PropertyRoute route)
        {
            if (pc.CustomWriteJsonProperty != null)
            {
                pc.CustomWriteJsonProperty(new WriteJsonPropertyContext
                {
                    JsonWriter          = writer,
                    JsonSerializer      = serializer,
                    LowerCaseName       = lowerCaseName,
                    Entity              = mod,
                    ParentPropertyRoute = route,
                    PropertyConverter   = pc
                });
            }
            else
            {
                var pr = route.Add(pc.PropertyValidator.PropertyInfo);

                string error = CanReadPropertyRoute?.Invoke(pr);

                if (error != null)
                {
                    return;
                }

                using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr))
                {
                    writer.WritePropertyName(lowerCaseName);
                    serializer.Serialize(writer, pc.GetValue(mod));
                }
            }
        }
예제 #2
0
        public void WriteJsonProperty(JsonWriter writer, JsonSerializer serializer, ModifiableEntity mod, string lowerCaseName, PropertyConverter pc, PropertyRoute route)
        {
            if (pc.CustomWriteJsonProperty != null)
            {
                pc.CustomWriteJsonProperty(new WriteJsonPropertyContext
                {
                    JsonWriter          = writer,
                    JsonSerializer      = serializer,
                    LowerCaseName       = lowerCaseName,
                    Entity              = mod,
                    ParentPropertyRoute = route,
                    PropertyConverter   = pc
                });
            }
            else
            {
                var pr = route.Add(pc.PropertyValidator.PropertyInfo);

                string error = CanReadPropertyRoute?.Invoke(pr);

                if (error != null)
                {
                    return;
                }

                using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr))
                {
                    writer.WritePropertyName(lowerCaseName);
                    var val = pc.GetValue(mod);
                    if (val is Lite <Entity> lite)
                    {
                        new LiteJsonConverter().WriteJson(writer, lite, serializer);
                    }
                    else
                    {
                        serializer.Serialize(writer, pc.GetValue(mod));
                    }

                    if (writer.WriteState == WriteState.Property)
                    {
                        throw new InvalidOperationException($"Impossible to serialize '{mod}' to JSON. Maybe there is a cycle?");
                    }
                }
            }
        }
        public void WriteJsonProperty(JsonWriter writer, JsonSerializer serializer, ModifiableEntity mod, string lowerCaseName, PropertyConverter pc, PropertyRoute route)
        {
            if (pc.CustomWriteJsonProperty != null)
            {
                pc.CustomWriteJsonProperty(new WriteJsonPropertyContext
                {
                    JsonWriter = writer,
                    JsonSerializer = serializer,
                    LowerCaseName = lowerCaseName,
                    Entity = mod,
                    ParentPropertyRoute = route,
                    PropertyConverter = pc
                });
            }
            else
            {
                var pr = route.Add(pc.PropertyValidator.PropertyInfo);

                string error = CanReadPropertyRoute?.Invoke(pr);

                if (error != null)
                    return;

                using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr))
                {
                    writer.WritePropertyName(lowerCaseName);
                    serializer.Serialize(writer, pc.GetValue(mod));
                }
            }
        }