HumanReadableSerializerOptions Class
Provides options for controlling the behavior of HumanReadableSerializer.
public sealed class HumanReadableSerializerOptions : IEquatable<HumanReadableSerializerOptions>Example
var options = new HumanReadableSerializerOptions
{
IncludeFields = true,
DefaultIgnoreCondition = HumanReadableIgnoreCondition.WhenWritingNull,
};
var obj = new { Name = "John Doe", Nickname = (string?)null };
var output = HumanReadableSerializer.Serialize(obj, options);
Assert.Equal("Name: John Doe", output);Constructors
| Name | Description |
|---|---|
| HumanReadableSerializerOptions() |
HumanReadableSerializerOptions()
HumanReadableSerializerOptions.cspublic HumanReadableSerializerOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| Converters | Gets the list of converters used for serialization. |
| DefaultIgnoreCondition | Gets or sets the default ignore condition for properties and fields. |
| DictionaryKeyOrder | Gets or sets the comparer used to sort dictionary keys when serializing dictionaries. |
| IncludeFields | Gets or sets whether to include public fields during serialization. |
| IncludeObsoleteMembers | Gets or sets whether to include members marked with the Obsolete attribute. |
| IsReadOnly | Gets whether this instance is read-only. |
| MaxDepth | Gets or sets the maximum depth allowed when serializing nested objects. |
| NewLine | Gets or sets the line terminator written between lines, either "\n" or "\r\n". The default is "\n" on every platform, so the output does not depend on the operating system. |
| PropertyOrder | Gets or sets the comparer used to sort property names when serializing objects. |
| ShowInvisibleCharactersInValues | Gets or sets whether to show invisible characters (like newlines and tabs) in values using Unicode control pictures. |
Converters
HumanReadableSerializerOptions.csGets the list of converters used for serialization.
public IList<HumanReadableConverter> Converters { get; }Property value
DefaultIgnoreCondition
HumanReadableSerializerOptions.csGets or sets the default ignore condition for properties and fields.
public HumanReadableIgnoreCondition DefaultIgnoreCondition { get; set; }Property value
DictionaryKeyOrder
HumanReadableSerializerOptions.csGets or sets the comparer used to sort dictionary keys when serializing dictionaries.
Property value
Remarks
When null, the keys of dictionaries that keep an order (for example Dictionary<TKey, TValue>) are written in enumeration order. The keys of hash-based collections that have no meaningful order (Hashtable, HybridDictionary and StringDictionary) are always sorted, using StringComparer.Ordinal by default, so the output does not depend on the process. The comparer also applies to the other non-generic IDictionary implementations.
IncludeFields
HumanReadableSerializerOptions.csIncludeObsoleteMembers
HumanReadableSerializerOptions.csIsReadOnly
HumanReadableSerializerOptions.csGets or sets the line terminator written between lines, either "\n" or "\r\n". The default is "\n" on every platform, so the output does not depend on the operating system.
public string NewLine { get; set; }Property value
Exceptions
ArgumentException- The value is neither
"\n"nor"\r\n".
Remarks
Line breaks inside serialized values are rewritten with this terminator too.
PropertyOrder
HumanReadableSerializerOptions.csGets or sets the comparer used to sort property names when serializing objects.
Property value
ShowInvisibleCharactersInValues
HumanReadableSerializerOptions.csGets or sets whether to show invisible characters (like newlines and tabs) in values using Unicode control pictures.
public bool ShowInvisibleCharactersInValues { get; set; }Property value
Remarks
Every value and property name is affected, including single-line ones. A space is kept between other characters, but written as ␠ at the start or the end of a line. The other space characters, the zero-width characters, the format characters (for example soft hyphens and bidirectional marks) and the C1 control characters, which have no control picture, are written as their code point, for example <U+00A0> for a no-break space.
Methods
AddAttribute overloads
AddAttribute(FieldInfo, HumanReadableAttribute)
HumanReadableSerializerOptions.csAdds an attribute to the specified field.
public void AddAttribute(FieldInfo member, HumanReadableAttribute attribute)Parameters
memberFieldInfo- The field to add the attribute to.
attributeHumanReadableAttribute- The attribute to add.
Remarks
The attribute applies when serializing the type the field is retrieved from (MemberInfo.ReflectedType) or a type deriving from it.
AddAttribute(PropertyInfo, HumanReadableAttribute)
HumanReadableSerializerOptions.csAdds an attribute to the specified property.
public void AddAttribute(PropertyInfo member, HumanReadableAttribute attribute)Parameters
memberPropertyInfo- The property to add the attribute to.
attributeHumanReadableAttribute- The attribute to add.
Remarks
The attribute applies when serializing the type the property is retrieved from (MemberInfo.ReflectedType) or a type deriving from it, including to the properties that override it.
AddAttribute(Type, HumanReadableAttribute)
HumanReadableSerializerOptions.csAdds an attribute to the specified type.
public void AddAttribute(Type type, HumanReadableAttribute attribute)Parameters
typeType- The type to add the attribute to.
attributeHumanReadableAttribute- The attribute to add.
Remarks
The attribute also applies to the types that derive from type or implement it, as an attribute declared on the type would.
AddAttribute(Type, string, HumanReadableAttribute)
HumanReadableSerializerOptions.csAdds an attribute to a member of the specified type.
public void AddAttribute(Type type, string memberName, HumanReadableAttribute attribute)Parameters
typeType- The type containing the member.
memberNamestring- The name of the member.
attributeHumanReadableAttribute- The attribute to add.
Remarks
The member can be declared in type or in one of its base types, including private members of the base types. The attribute applies when serializing type or a type deriving from it, including to the members that override the member.
AddAttribute<T>(Expression<Func<T, object>>, HumanReadableAttribute)
HumanReadableSerializerOptions.csAdds an attribute to a member identified by an expression.
public void AddAttribute<T>(Expression<Func<T, object>> member, HumanReadableAttribute attribute)Type parameters
T- The type containing the member.
Parameters
memberExpression<Func<T, object>>- An expression identifying the member, such as
x => x.Name, or several members, such asx => new { x.Name, x.Age }. attributeHumanReadableAttribute- The attribute to add.
Remarks
The attribute applies to the member when serializing the type it is accessed on, or a type deriving from it, including to the members that override it. For x => x.Name, this is T. An attribute belongs to a member, not to a path in the object graph: for x => x.Address.City, the attribute applies to the City member of every Address instance, wherever it is.
AddFieldAttribute(Func<FieldInfo, bool>, HumanReadableAttribute)
HumanReadableSerializerOptions.csAdds an attribute to all fields matching the specified condition.
public void AddFieldAttribute(Func<FieldInfo, bool> condition, HumanReadableAttribute attribute)Parameters
conditionFunc<FieldInfo, bool>- A function that determines which fields to add the attribute to.
attributeHumanReadableAttribute- The attribute to add.
AddFormatter(string, ValueFormatter)
HumanReadableSerializerOptions.csAdds a value formatter for the specified media type.
public void AddFormatter(string mediaType, ValueFormatter formatter)Parameters
mediaTypestring- The media type (e.g., "application/json", "text/xml").
formatterValueFormatter- The formatter to use for the media type.
AddPropertyAttribute(Func<PropertyInfo, bool>, HumanReadableAttribute)
HumanReadableSerializerOptions.csAdds an attribute to all properties matching the specified condition.
public void AddPropertyAttribute(Func<PropertyInfo, bool> condition, HumanReadableAttribute attribute)Parameters
conditionFunc<PropertyInfo, bool>- A function that determines which properties to add the attribute to.
attributeHumanReadableAttribute- The attribute to add.
AddTypeAttribute(Func<Type, bool>, HumanReadableAttribute)
HumanReadableSerializerOptions.csAdds an attribute to all types matching the specified condition.
public void AddTypeAttribute(Func<Type, bool> condition, HumanReadableAttribute attribute)Parameters
conditionFunc<Type, bool>- A function that determines which types to add the attribute to.
attributeHumanReadableAttribute- The attribute to add.
Equals overloads
Equals(HumanReadableSerializerOptions?)
public bool Equals(HumanReadableSerializerOptions? other)No documentation is available.
Equals(object?)
GetFormatter(string)
HumanReadableSerializerOptions.cspublic ValueFormatter? GetFormatter(string mediaType)No documentation is available.
GetHashCode()
GetOrSetSerializationData<T>(string, Func<T>)
HumanReadableSerializerOptions.csGets or creates serialization data for the current serialization scope.
MakeReadOnly()
HumanReadableSerializerOptions.csMakes this instance read-only, preventing further modifications.
public void MakeReadOnly()ToString()
Operators
| Name | Description |
|---|---|
| operator ==(HumanReadableSerializerOptions?, HumanReadableSerializerOptions?) | |
| operator !=(HumanReadableSerializerOptions?, HumanReadableSerializerOptions?) |
operator ==(HumanReadableSerializerOptions?, HumanReadableSerializerOptions?)
public static bool operator ==(HumanReadableSerializerOptions? left, HumanReadableSerializerOptions? right)No documentation is available.
operator !=(HumanReadableSerializerOptions?, HumanReadableSerializerOptions?)
public static bool operator !=(HumanReadableSerializerOptions? left, HumanReadableSerializerOptions? right)No documentation is available.