Class JsonConverterCollectionExtensions
- 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
converters
ICollection<JsonConverter>The ICollection{JsonConverter} to extend.
Returns
- ICollection<JsonConverter>
A reference to
converters
after 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
converters
ICollection<JsonConverter>The ICollection{JsonConverter} to extend.
format
StringA standard or custom date and time format string.
provider
CultureInfoAn object that supplies culture-specific formatting information.
Returns
- ICollection<JsonConverter>
A reference to
converters
after 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>, Boolean, Boolean)
Adds an Exception JSON converter to the list.
public static ICollection<JsonConverter> AddExceptionConverter(this ICollection<JsonConverter> converters, bool includeStackTrace, bool includeData)
Parameters
converters
ICollection<JsonConverter>The ICollection{JsonConverter} to extend.
includeStackTrace
BooleanThe value that determine whether the stack of an exception is included in the converted result.
includeData
BooleanThe value that determine whether the data of an exception is included in the converted result.
Returns
- ICollection<JsonConverter>
A reference to
converters
after 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
converters
ICollection<JsonConverter>The ICollection{JsonConverter} to extend.
setup
Action<ExceptionDescriptorOptions>The ExceptionDescriptorOptions which may be configured.
afterWriteErrorStartObject
Utf8JsonWriterAction<T>The delegate that is invoked just after writing JSON start object (
Error
).beforeWriteEndObject
Utf8JsonWriterAction<T>The delegate that is invoked just before writing the JSON end object.
Returns
- ICollection<JsonConverter>
A reference to
converters
after 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
converters
ICollection<JsonConverter>The ICollection{JsonConverter} to extend.
Returns
- ICollection<JsonConverter>
A reference to
converters
after 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
converters
ICollection<JsonConverter>The ICollection{JsonConverter} to extend.
namingPolicy
JsonNamingPolicyThe optional naming policy for writing enum values.
Returns
- ICollection<JsonConverter>
A reference to
converters
after 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
converters
ICollection<JsonConverter>The ICollection{JsonConverter} to extend.
Returns
- ICollection<JsonConverter>
A reference to
converters
after 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
converters
ICollection<JsonConverter>The ICollection{JsonConverter} to extend.
Returns
- ICollection<JsonConverter>
A reference to
converters
after the operation has completed.
RemoveAllOf(ICollection<JsonConverter>, 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
converters
ICollection<JsonConverter>The collection of JsonConverter to extend.
types
Type[]The type of objects or values handled by a sequence of JsonConverter.
Returns
- ICollection<JsonConverter>
A reference to
converters
so that additional calls can be chained.
Exceptions
- ArgumentNullException
converters
cannot 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
converters
ICollection<JsonConverter>The collection of JsonConverter to extend.
Returns
- ICollection<JsonConverter>
A reference to
converters
so that additional calls can be chained.
Type Parameters
T
The type of object or value handled by the JsonConverter.
Exceptions
- ArgumentNullException
converters
cannot be null.