Class SerializerMemberAttribute

Attach this attribute to a method, field, or property to expose it as serializable and configure it's "ShouldSerialize", "Formatter", "Order", and "EmitDefaultValue" behaviors.

If attached to a property, the propery must have a getter and take no parameters.

If attached to a method, the method must return a non-null value and either:

  • be an instance method and
  • take no parameters
  • take one parameter, an in WriteContext
  • be static and
  • take no parameters
  • take one parameter either
  • an in WriteContext or
  • a type to which the declaring type of this member can be assigned
  • take two parameters
  1. a type to which the declaring type of this member can be assigned
  2. in WriteContext
Inheritance
System.Object
SerializerMemberAttribute
Implements
System.IEquatable<SerializerMemberAttribute>
Namespace: Cesil
Assembly: Cesil.dll
Syntax
public sealed class SerializerMemberAttribute : Attribute, IEquatable<SerializerMemberAttribute>

Constructors

SerializerMemberAttribute()

Create a SerializerMemberAttribute attribute.

This will expose the member for serialization if it would not otherwise be exposed.

If on a method, a Name must be set.

Declaration
public SerializerMemberAttribute()

Properties

EmitDefaultValue

Whether or not to emit the default value.

Defaults to Yes.

Declaration
public EmitDefaultValue EmitDefaultValue { get; set; }
Property Value
Type Description
EmitDefaultValue

FormatterMethodName

Name of formatter method, used with FormatterType.

If non-null, FormatterType must also be set.

The method must:

  • be public (or internal, if declared in the same assembly as the annotated type)
  • static
  • return bool
  • have three paramters:
  1. a type which the annotated member's type can be assigned to
  2. in WriteContext
  3. IBufferWriter(char)
Declaration
public string FormatterMethodName { get; set; }
Property Value
Type Description
System.String

FormatterType

Type to lookup a formatter method on, used with FormatterMethodName.

If null, defaults to a built in Formatter for the type of this member (if any).

If non-null, FormatterMethodName must also be set.

The type must be public (or internal, if declared in the same assembly as the annotated type).

Declaration
public Type FormatterType { get; set; }
Property Value
Type Description
System.Type

HasOrder

Returns true if Order has been explicitly set.

Getting Order when HasOrder is false will throw an exception.

Declaration
public bool HasOrder { get; }
Property Value
Type Description
System.Boolean

Name

The name of the column this member's returned value will be serialized under.

For fields and properties, this defaults to their declared name.

For methods, this must be explicitly set.

Declaration
public string Name { get; set; }
Property Value
Type Description
System.String

Order

Value used to order columns.

Set to null to leave order unspecified.

Orders with explicit values are sorted before those without values.

Check HashOrder before getting Order, or an exception will be thrown.

Declaration
public int Order { get; set; }
Property Value
Type Description
System.Int32

ShouldSerializeMethodName

Name of should serialize method, used with ShouldSerializeType.

If non-null, ShouldSerializeType must also be set.

The method must either

  • be public (or internal, if declared in the same assembly as the annotated type)
  • instance method
  • take
  1. no parameters
  2. one in WriteContext parameter
  • return bool or
  • be public (or internal, if declared in the same assembly as the annotated type)
  • static
  • take
  1. no parameters
  2. one parameter of a type which declares the annotated member
  3. two parameters
  4. a type which declares the annotated member
  5. in WriteContext
  • return bool
Declaration
public string ShouldSerializeMethodName { get; set; }
Property Value
Type Description
System.String

ShouldSerializeType

Type to lookup a should serialize method on, used with ShouldSerializeMethodName.

If null, no should seralize is used.

If non-null, ShouldSerializeMethodName must also be set.

The type must be public (or internal, if declared in the same assembly as the annotated type).

Declaration
public Type ShouldSerializeType { get; set; }
Property Value
Type Description
System.Type

Methods

Equals(SerializerMemberAttribute)

Returns true if the given SerializerMemberAttribute is equal to this one.

Declaration
public bool Equals(SerializerMemberAttribute attribute)
Parameters
Type Name Description
SerializerMemberAttribute attribute
Returns
Type Description
System.Boolean

Equals(Object)

Return true if the given object is a SerializerMemberAttribute equal to this one.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj
Returns
Type Description
System.Boolean

GetHashCode()

Returns a hash code for this SerializerMemberAttribute.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

ToString()

Returns a representation of this SerializerMemberAttribute object.

Only for debugging, this value is not guaranteed to be stable.

Declaration
public override string ToString()
Returns
Type Description
System.String

Operators

Equality(SerializerMemberAttribute, SerializerMemberAttribute)

Compare two SerializerMemberAttributes for equality

Declaration
public static bool operator ==(SerializerMemberAttribute a, SerializerMemberAttribute b)
Parameters
Type Name Description
SerializerMemberAttribute a
SerializerMemberAttribute b
Returns
Type Description
System.Boolean

Inequality(SerializerMemberAttribute, SerializerMemberAttribute)

Compare two SerializerMemberAttributes for inequality

Declaration
public static bool operator !=(SerializerMemberAttribute a, SerializerMemberAttribute b)
Parameters
Type Name Description
SerializerMemberAttribute a
SerializerMemberAttribute b
Returns
Type Description
System.Boolean

Implements

System.IEquatable<>
In This Article
Back to top Generated by DocFX