Skip to content
kevin-montrose edited this page Apr 10, 2021 · 6 revisions

Resets

Introduction

The Reset class represents a callback that occurs prior to setting a member during deserialization. Resets are only used during static deserialization.

The name is taken from the ResetXXX() pattern introduced by Windows Forms, and adopted by other deserializers in the .NET world (like System.XML, and protobuf-net).

Supported Backers

Reset instances can be backed by methods, and delegates.

Delegates

A Reset may be backed by two different types of delegates:

  • delegates of the form void Name(in ReadContext)
  • delegates of the form void Name(RowType, in ReadContext)

They differ by whether or not they take the row being deserialized as a parameter.

Cesil provides StaticResetDelegate, ResetDelegate<TRow> and Reset.ForDelegate<...>(...) overloads which conform to these forms. You can also explicitly cast any delegate to a Reset, provided it is logically equivalent to StaticResetDelegate or ResetDelegate<TRow>.

Methods

A Reset can be backed by many different kinds of MethodInfo.

All supported methods must have a void return.

A static method must either:

  • have zero parameters or
  • have one parameter of the row type or
  • have one parameter of in ReadContext type or
  • have two parameters, the first of the row type and the second of in ReadContext type

An instance method must:

  • be on the row type and have zero parameters
  • be on the row type, and take a single in ReadContext parameter

Use the Reset.ForMethod(MethodInfo) method to create a Reset backed by a method. You can also explicitly cast any MethodInfo to a Reset, provided it follows the above rules.

Explicit Casts

Cesil provides explicit casts of MethodInfo, and Delegate to Reset. These are roughly equivalent to calling the static ForXXX(...) methods on Reset, but differ by allowing null values.

Clone this wiki locally