/// <summary>
 /// Configures <see cref="JsonSerializerSettings"/> to serialize <see cref="IPropertyContainer"/>.
 /// The same as <see cref="ConfigureJsonForPropertyContainers"/>.
 /// </summary>
 /// <param name="jsonSerializerSettings"><see cref="JsonSerializerSettings"/> instance.</param>
 /// <param name="configureSerialization">Optional action to configure metadata serialization.</param>
 /// <param name="metadataJsonSerializationOptions">Optional metadata serialization options.</param>
 /// <returns>The same options.</returns>
 public static JsonSerializerSettings ConfigureForMetadata(
     this JsonSerializerSettings jsonSerializerSettings,
     Action <MetadataJsonSerializationOptions>?configureSerialization  = null,
     MetadataJsonSerializationOptions?metadataJsonSerializationOptions = null)
 {
     return(jsonSerializerSettings.ConfigureJsonForPropertyContainers(configureSerialization, metadataJsonSerializationOptions));
 }
Ejemplo n.º 2
0
        public static string ToJsonWithNewtonsoftJson <T>(this T entity, Action <JsonSerializerSettings>?configureJsonSerializerSettings = null, Action <MetadataJsonSerializationOptions>?configureSerialization = null)
        {
            JsonSerializerSettings serializerSettings = new JsonSerializerSettings();

            configureJsonSerializerSettings?.Invoke(serializerSettings);
            var jsonSerializerSettings = serializerSettings.ConfigureJsonForPropertyContainers(configureSerialization);

            return(JsonConvert.SerializeObject(entity, Formatting.Indented, jsonSerializerSettings));
        }