Version 3.3.0.1

FormatterEmitter class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public static class FormatterEmitter
Utility class for emitting formatters using the System.Reflection.Emit namespace.

NOTE: Some platforms do not support emitting. Check whether you can emit on the current platform using Sirenix.Serialization.Utilities.EmitUtilities.CanEmit.

Inheritance
  • System.Object
  • FormatterEmitter

Fields

PRE_EMITTED_ASSEMBLY_NAME
The name of the pre-generated assembly that contains pre-emitted formatters for use on AOT platforms where emitting is not supported. Note that this assembly is not always present.
public const string PRE_EMITTED_ASSEMBLY_NAME = "Sirenix.Serialization.AOTGenerated"
RUNTIME_EMITTED_ASSEMBLY_NAME
The name of the runtime-generated assembly that contains runtime-emitted formatters for use on non-AOT platforms where emitting is supported. Note that this assembly is not always present.
public const string RUNTIME_EMITTED_ASSEMBLY_NAME = "Sirenix.Serialization.RuntimeEmitted"

Methods

EmitAOTFormatter(Type, ModuleBuilder, ISerializationPolicy)
Emits a formatter for a given type into a given module builder, using a given serialization policy to determine which members to serialize.
public static Type EmitAOTFormatter(Type formattedType, ModuleBuilder moduleBuilder, ISerializationPolicy policy)
Parameters
System.Type formattedType

Type to create a formatter for.

System.Reflection.Emit.ModuleBuilder moduleBuilder

The module builder to emit a formatter into.

Sirenix.Serialization.ISerializationPolicy policy

The serialization policy to use for creating the formatter.

Returns
System.Type

The fully constructed, emitted formatter type.

GetEmittedFormatter(Type, ISerializationPolicy)
Gets an emitted formatter for a given type.

NOTE: Some platforms do not support emitting. On such platforms, this method logs an error and returns null. Check whether you can emit on the current platform using Sirenix.Serialization.Utilities.EmitUtilities.CanEmit.

public static IFormatter GetEmittedFormatter(Type type, ISerializationPolicy policy)
Parameters
System.Type type

The type to emit a formatter for.

Sirenix.Serialization.ISerializationPolicy policy

The serialization policy to use to determine which members the emitted formatter should serialize. If null, Strict is used.

Returns
Sirenix.Serialization.IFormatter

The type of the emitted formatter.

Exceptions
System.ArgumentNullException

The type argument is null.