Class DefaultTypeDescriber

The default implementation of ITypeDescriber used to determine how to (de)serialize types and how to convert dynamic cells and rows.

It will serialize all public properties, any fields with a [DataMember], and will respect ShouldSerialize() methods.

It will deserialize all public properties, any fields with a [DataMember], and will call Reset() methods. Expects a public parameterless constructor for any deserialized types.

It will also deserialize records using their primary constructor. Names, Parsers, Resets, and Order may be customized with records but not Setters and MemberRequireds.

It will convert dynamic cells to most built-in types, and map dynamoc rows to POCOs, ValueTuples, Tuples, and IEnumerables.

This type is unsealed to allow for easy extension of it's behavior.

Inheritance
System.Object
DefaultTypeDescriber
Implements
ITypeDescriber
Namespace: Cesil
Assembly: Cesil.dll
Syntax
public class DefaultTypeDescriber : Object, IDelegateCache, ITypeDescriber

Constructors

DefaultTypeDescriber()

Construct a new DefaultTypeDesciber.

A pre-allocated instance is available on TypeDescribers.Default.

Declaration
public DefaultTypeDescriber()

Methods

ClearCache()

Clears any internal caches this instance has created.

Caches may be used to accelerate member lookup or dynamic operations.

Clearing caches is not necessary for correct functioning, but may be useful to manage memory use.

Declaration
public void ClearCache()

EnumerateMembersToDeserialize(TypeInfo)

Enumerate all columns to deserialize.

Declaration
public virtual IEnumerable<DeserializableMember> EnumerateMembersToDeserialize(TypeInfo forType)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
Returns
Type Description
System.Collections.Generic.IEnumerable<DeserializableMember>

EnumerateMembersToSerialize(TypeInfo)

Enumerate all columns to deserialize.

Declaration
public virtual IEnumerable<SerializableMember> EnumerateMembersToSerialize(TypeInfo forType)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
Returns
Type Description
System.Collections.Generic.IEnumerable<SerializableMember>

GetCellsForDynamicRow(WriteContext, Object, Span<DynamicCellValue>)

Discovers cells for the given dynamic row.

If the span is too small, the needed size is returned and the span is left in an indeterminate state.

Null rows have no cells, but are legal.

Rows created by Cesil have their cells enumerated as strings.

Other dynamic types will have each member enumerated as either their actual type (if a formatter is available) or as a string.

Override to tweak behavior.

Declaration
public virtual int GetCellsForDynamicRow(in WriteContext context, dynamic row, Span<DynamicCellValue> cells)
Parameters
Type Name Description
WriteContext context
System.Object row
System.Span<DynamicCellValue> cells
Returns
Type Description
System.Int32

GetDeserializationName(TypeInfo, FieldInfo)

Returns the name of the column that should map to the given field when deserialized.

Override to tweak behavior.

Declaration
protected virtual string GetDeserializationName(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
System.String

GetDeserializationName(TypeInfo, ParameterInfo)

Returns the name of the column that should map to the given constructor parameter when deserialized.

Override to tweak behavior.

Declaration
protected virtual string GetDeserializationName(TypeInfo forType, ParameterInfo parameter)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.ParameterInfo parameter
Returns
Type Description
System.String

GetDeserializationName(TypeInfo, PropertyInfo)

Returns the name of the column that should map to the given property when deserialized.

Override to tweak behavior.

Declaration
protected virtual string GetDeserializationName(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
System.String

GetDynamicCellParserFor(ReadContext, TypeInfo)

Returns a Parser that can be used to parse the targetType.

Override to customize behavior.

Declaration
public virtual Parser GetDynamicCellParserFor(in ReadContext context, TypeInfo targetType)
Parameters
Type Name Description
ReadContext context
System.Reflection.TypeInfo targetType
Returns
Type Description
Parser

GetDynamicRowConverter(ReadContext, IEnumerable<ColumnIdentifier>, TypeInfo)

Returns a DynamicRowConverter that can be used to parse the targetType, if a default parser for the type exists or a constructor accepting the appropriate number of objects (can be dynamic in source) is on the type.

Declaration
public virtual DynamicRowConverter GetDynamicRowConverter(in ReadContext context, IEnumerable<ColumnIdentifier> columns, TypeInfo targetType)
Parameters
Type Name Description
ReadContext context
System.Collections.Generic.IEnumerable<ColumnIdentifier> columns
System.Reflection.TypeInfo targetType
Returns
Type Description
DynamicRowConverter

GetEmitDefaultValue(TypeInfo, FieldInfo)

Returns whether or not the default value should be serialized for the given property.

For reference types, the default value is null. For ValueTypes the default value is either 0 or the equivalent of initializing all of it's fields with their default values.

Override to tweak behavior.

Declaration
protected virtual EmitDefaultValue GetEmitDefaultValue(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
EmitDefaultValue

GetEmitDefaultValue(TypeInfo, PropertyInfo)

Returns whether or not the default value should be serialized for the given property.

For reference types, the default value is null. For ValueTypes the default value is either 0 or the equivalent of initializing all of it's fields with their default values.

Override to tweak behavior.

Declaration
protected virtual EmitDefaultValue GetEmitDefaultValue(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
EmitDefaultValue

GetFormatter(TypeInfo)

Returns the formatter to use for the given type.

If you do not care about the member being parsed, override just this method as the other GetFormatter(...) methods delegate to it.

Override to tweak behavior.

Declaration
protected virtual Formatter GetFormatter(TypeInfo t)
Parameters
Type Name Description
System.Reflection.TypeInfo t
Returns
Type Description
Formatter

GetFormatter(TypeInfo, FieldInfo)

Returns the formatter to use for the column that maps to the given field when serialized.

Override to tweak behavior.

Declaration
protected virtual Formatter GetFormatter(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
Formatter

GetFormatter(TypeInfo, PropertyInfo)

Returns the formatter to use for the column that maps to the given property when serialized.

Override to tweak behavior.

Declaration
protected virtual Formatter GetFormatter(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
Formatter

GetFormatter(TypeInfo, String, WriteContext, Object)

Called in GetCellsForDynamicRow to determine the formatter that should be used for a cell.

Override to customize behavior.

Declaration
protected virtual Formatter GetFormatter(TypeInfo forType, string name, in WriteContext context, dynamic row)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.String name
WriteContext context
System.Object row
Returns
Type Description
Formatter

GetGetter(TypeInfo, FieldInfo)

Returns the getter to use for the given field when serialized.

Override to tweak behavior.

Declaration
protected virtual Getter GetGetter(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
Getter

GetGetter(TypeInfo, PropertyInfo)

Returns the getter to use for the given property when serialized.

Override to tweak behavior.

Declaration
protected virtual Getter GetGetter(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
Getter

GetInstanceProvider(TypeInfo)

Gets an InstanceProvider that wraps the parameterless constructor for reference types, and the zero value for value types.

Returns null if no InstanceProvider can be found.

Declaration
public virtual InstanceProvider GetInstanceProvider(TypeInfo forType)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
Returns
Type Description
InstanceProvider

GetIsRequired(TypeInfo, FieldInfo)

Returns whether or not the given field is required during deserialization.

Override to tweak behavior.

Declaration
protected virtual MemberRequired GetIsRequired(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
MemberRequired

GetIsRequired(TypeInfo, PropertyInfo)

Returns whether or not the given property is required during deserialization.

Override to tweak behavior.

Declaration
protected virtual MemberRequired GetIsRequired(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
MemberRequired

GetOrder(TypeInfo, FieldInfo)

Returns the index of the column that should map to the given field. Headers can change this during deserialization.

Return null to leave order unspecified.

Override to tweak behavior.

Declaration
protected virtual Nullable<int> GetOrder(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
System.Nullable<System.Int32>

GetOrder(TypeInfo, ParameterInfo)

Returns the index of the column that should map to the given constructor parameter. Headers can change this during deserialization.

Return null to leave order unspecified.

Override to tweak behavior.

Declaration
protected virtual Nullable<int> GetOrder(TypeInfo forType, ParameterInfo parameter)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.ParameterInfo parameter
Returns
Type Description
System.Nullable<System.Int32>

GetOrder(TypeInfo, PropertyInfo)

Returns the index of the column that should map to the given property. Headers can change this during deserialization.

Return null to leave order unspecified.

Override to tweak behavior.

Declaration
protected virtual Nullable<int> GetOrder(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
System.Nullable<System.Int32>

GetParser(TypeInfo)

Returns the parser to use for the given type.

If you do not care about the member being parsed, override just this method as the other GetParser(...) methods delegate to it.

Override to tweak behavior.

Declaration
public virtual Parser GetParser(TypeInfo forType)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
Returns
Type Description
Parser

GetParser(TypeInfo, FieldInfo)

Returns the parser to use for the column that maps to the given field when deserialized.

Override to tweak behavior.

Declaration
protected virtual Parser GetParser(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
Parser

GetParser(TypeInfo, ParameterInfo)

Returns the parser to use for the column that maps to the given constructor parameter when deserialized.

Override to tweak behavior.

Declaration
protected virtual Parser GetParser(TypeInfo forType, ParameterInfo parameter)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.ParameterInfo parameter
Returns
Type Description
Parser

GetParser(TypeInfo, PropertyInfo)

Returns the parser to use for the column that maps to the given property when deserialized.

Override to tweak behavior.

Declaration
protected virtual Parser GetParser(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
Parser

GetReset(TypeInfo, FieldInfo)

Returns the reset method, if any, to call prior to deserializing the given field.

Override to tweak behavior.

Declaration
protected virtual Reset GetReset(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
Reset

GetReset(TypeInfo, ParameterInfo)

Returns the reset method, if any, to call prior to deserializing the given constructor parameter.

Override to tweak behavior.

Declaration
protected virtual Reset GetReset(TypeInfo forType, ParameterInfo parameter)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.ParameterInfo parameter
Returns
Type Description
Reset

GetReset(TypeInfo, PropertyInfo)

Returns the reset method, if any, to call prior to deserializing the given property.

Override to tweak behavior.

Declaration
protected virtual Reset GetReset(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
Reset

GetSerializationName(TypeInfo, FieldInfo)

Returns the name of the column that should map to the given field when serialized.

Override to tweak behavior.

Declaration
protected virtual string GetSerializationName(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
System.String

GetSerializationName(TypeInfo, PropertyInfo)

Returns the name of the column that should map to the given property when serialized.

Override to tweak behavior.

Declaration
protected virtual string GetSerializationName(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
System.String

GetSetter(TypeInfo, FieldInfo)

Returns the setter to use for the given field when deserialized.

Override to tweak behavior.

Declaration
protected virtual Setter GetSetter(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
Setter

GetSetter(TypeInfo, PropertyInfo)

Returns the setter to use for the given property when deserialized.

Override to tweak behavior.

Declaration
protected virtual Setter GetSetter(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
Setter

GetShouldSerialize(TypeInfo, FieldInfo)

Returns the ShouldSerializeXXX()-style method to use for the given field when serializing, if any. By default, always returns null.

If specified, the method will be invoked for each record to determine whether to write the field.

Override to tweak behavior.

Declaration
protected virtual ShouldSerialize GetShouldSerialize(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
ShouldSerialize

GetShouldSerialize(TypeInfo, PropertyInfo)

Returns the ShouldSerializeXXX()-style method to use for the given property when serializing, if any.

If specified, the method will be invoked for each record to determine whether to write the property.

Override to tweak behavior.

Declaration
protected virtual ShouldSerialize GetShouldSerialize(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
ShouldSerialize

ShouldDeserialize(TypeInfo, FieldInfo)

Returns true if the given field should be deserialized.

Override to tweak behavior.

Declaration
protected virtual bool ShouldDeserialize(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
System.Boolean

ShouldDeserialize(TypeInfo, PropertyInfo)

Returns true if the given property should be deserialized.

Override to tweak behavior.

Declaration
protected virtual bool ShouldDeserialize(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
System.Boolean

ShouldIncludeCell(String, WriteContext, Object)

Called in GetCellsForDynamicRow to determine whether a cell should be included.

Override to customize behavior.

Declaration
protected virtual bool ShouldIncludeCell(string name, in WriteContext context, dynamic row)
Parameters
Type Name Description
System.String name
WriteContext context
System.Object row
Returns
Type Description
System.Boolean

ShouldSerialize(TypeInfo, FieldInfo)

Returns true if the given field should be serialized.

Override to tweak behavior.

Declaration
protected virtual bool ShouldSerialize(TypeInfo forType, FieldInfo field)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.FieldInfo field
Returns
Type Description
System.Boolean

ShouldSerialize(TypeInfo, PropertyInfo)

Returns true if the given property should be serialized.

Override to tweak behavior.

Declaration
protected virtual bool ShouldSerialize(TypeInfo forType, PropertyInfo property)
Parameters
Type Name Description
System.Reflection.TypeInfo forType
System.Reflection.PropertyInfo property
Returns
Type Description
System.Boolean

ToString()

Returns a representation of this DefaultTypeDescriber object.

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

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

Implements

ITypeDescriber
In This Article
Back to top Generated by DocFX