Class JsonConverterCollectionExtensions
- Namespace
- Cuemon.Extensions.Text.Json.Converters
- Assembly
- Cuemon.Extensions.Text.Json.dll
Extension methods for the JsonConverter class.
public static class JsonConverterCollectionExtensions
- Inheritance
-
JsonConverterCollectionExtensions
Methods
AddDataPairConverter(ICollection<JsonConverter>)
Adds an DataPair JSON converter to the list.
public static ICollection<JsonConverter> AddDataPairConverter(this ICollection<JsonConverter> converters)
Parameters
convertersICollection<JsonConverter>The ICollection{JsonConverter} to extend.
Returns
- ICollection<JsonConverter>
A reference to
convertersafter the operation has completed.
AddDateTimeConverter(ICollection<JsonConverter>, string, CultureInfo)
Adds a configurable DateTime JSON converter to the list.
public static ICollection<JsonConverter> AddDateTimeConverter(this ICollection<JsonConverter> converters, string format = "O", CultureInfo provider = null)
Parameters
convertersICollection<JsonConverter>The ICollection{JsonConverter} to extend.
formatstringA standard or custom date and time format string.
providerCultureInfoAn object that supplies culture-specific formatting information.
Returns
- ICollection<JsonConverter>
A reference to
convertersafter the operation has completed.
Examples
var formatter = new JsonFormatter(o => o.Settings.Converters.AddDateTimeConverter());
Remarks
If you miss the opportunity to configure DateTime format handling like you could with Newtonsoft.JSON, here is an alternative way. Default is "O" (https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#table-of-format-specifiers).
AddExceptionConverter(ICollection<JsonConverter>, bool, bool)
Adds an Exception JSON converter to the list.
public static ICollection<JsonConverter> AddExceptionConverter(this ICollection<JsonConverter> converters, bool includeStackTrace, bool includeData)
Parameters
convertersICollection<JsonConverter>The ICollection{JsonConverter} to extend.
includeStackTraceboolThe value that determine whether the stack of an exception is included in the converted result.
includeDataboolThe value that determine whether the data of an exception is included in the converted result.
Returns
- ICollection<JsonConverter>
A reference to
convertersafter the operation has completed.
AddExceptionDescriptorConverterOf<T>(ICollection<JsonConverter>, Action<ExceptionDescriptorOptions>, Utf8JsonWriterAction<T>, Utf8JsonWriterAction<T>)
Adds an ExceptionDescriptor JSON converter to the list.
public static ICollection<JsonConverter> AddExceptionDescriptorConverterOf<T>(this ICollection<JsonConverter> converters, Action<ExceptionDescriptorOptions> setup = null, Utf8JsonWriterAction<T> afterWriteErrorStartObject = null, Utf8JsonWriterAction<T> beforeWriteEndObject = null) where T : ExceptionDescriptor
Parameters
convertersICollection<JsonConverter>The ICollection{JsonConverter} to extend.
setupAction<ExceptionDescriptorOptions>The ExceptionDescriptorOptions which may be configured.
afterWriteErrorStartObjectUtf8JsonWriterAction<T>The delegate that is invoked just after writing JSON start object (
Error).beforeWriteEndObjectUtf8JsonWriterAction<T>The delegate that is invoked just before writing the JSON end object.
Returns
- ICollection<JsonConverter>
A reference to
convertersafter the operation has completed.
Type Parameters
T
AddFailureConverter(ICollection<JsonConverter>)
Adds a Failure JSON converter to the list.
public static ICollection<JsonConverter> AddFailureConverter(this ICollection<JsonConverter> converters)
Parameters
convertersICollection<JsonConverter>The ICollection{JsonConverter} to extend.
Returns
- ICollection<JsonConverter>
A reference to
convertersafter the operation has completed.
AddStringEnumConverter(ICollection<JsonConverter>, JsonNamingPolicy)
Adds an Enum JSON converter to the list.
public static ICollection<JsonConverter> AddStringEnumConverter(this ICollection<JsonConverter> converters, JsonNamingPolicy namingPolicy = null)
Parameters
convertersICollection<JsonConverter>The ICollection{JsonConverter} to extend.
namingPolicyJsonNamingPolicyThe optional naming policy for writing enum values.
Returns
- ICollection<JsonConverter>
A reference to
convertersafter the operation has completed.
Remarks
Default implementation will, just like Newtonsoft.Json variant, favor StringEnumConverter with a fallback to JsonStringEnumConverter using default naming policy from JsonFormatterOptions.
AddStringFlagsEnumConverter(ICollection<JsonConverter>)
Adds a combined Enum and FlagsAttribute JSON converter to the list.
public static ICollection<JsonConverter> AddStringFlagsEnumConverter(this ICollection<JsonConverter> converters)
Parameters
convertersICollection<JsonConverter>The ICollection{JsonConverter} to extend.
Returns
- ICollection<JsonConverter>
A reference to
convertersafter the operation has completed.
AddTransientFaultExceptionConverter(ICollection<JsonConverter>)
Adds a TransientFaultException JSON converter to the list.
public static ICollection<JsonConverter> AddTransientFaultExceptionConverter(this ICollection<JsonConverter> converters)
Parameters
convertersICollection<JsonConverter>The ICollection{JsonConverter} to extend.
Returns
- ICollection<JsonConverter>
A reference to
convertersafter the operation has completed.
RemoveAllOf(ICollection<JsonConverter>, params Type[])
Removes one or more JsonConverter implementations where CanConvert(Type) evaluates true in the collection of converters.
public static ICollection<JsonConverter> RemoveAllOf(this ICollection<JsonConverter> converters, params Type[] types)
Parameters
convertersICollection<JsonConverter>The collection of JsonConverter to extend.
typesType[]The type of objects or values handled by a sequence of JsonConverter.
Returns
- ICollection<JsonConverter>
A reference to
convertersso that additional calls can be chained.
Exceptions
- ArgumentNullException
converterscannot be null.
RemoveAllOf<T>(ICollection<JsonConverter>)
Removes one or more JsonConverter implementations where CanConvert(Type) evaluates true in the collection of converters.
public static ICollection<JsonConverter> RemoveAllOf<T>(this ICollection<JsonConverter> converters)
Parameters
convertersICollection<JsonConverter>The collection of JsonConverter to extend.
Returns
- ICollection<JsonConverter>
A reference to
convertersso that additional calls can be chained.
Type Parameters
TThe type of object or value handled by the JsonConverter.
Exceptions
- ArgumentNullException
converterscannot be null.