Version 3.3.0.1

FormatterUtilities class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public static class FormatterUtilities
Provides an array of utility methods which are commonly used by serialization formatters.
Inheritance
  • System.Object
  • FormatterUtilities

Methods

CreateUnityNull(Type, Type)
Creates a fake Unity null value of a given type, for the given UnityEngine.Object-derived owning type.

Unity uses these kinds of values to indicate missing object references.

public static Object CreateUnityNull(Type nullType, Type owningType)
Parameters
System.Type nullType

Type of the null value.

System.Type owningType

Type of the owning value. This is the value which changes the UnityEngine.MissingReferenceException which you get.

Returns
UnityEngine.Object

A fake Unity null value of a given type.

Exceptions
System.ArgumentNullException

The nullType or owningType parameter is null.

System.ArgumentException

The type given in the nullType parameter is not a Unity object. or The type given in the owningType parameter is not a Unity object.

GetContainedType(MemberInfo)
Gets the type contained in the given System.Reflection.MemberInfo. Currently only System.Reflection.FieldInfo and System.Reflection.PropertyInfo is supported.
public static Type GetContainedType(MemberInfo member)
Parameters
System.Reflection.MemberInfo member

The System.Reflection.MemberInfo to get the contained type of.

Returns
System.Type

The type contained in the given System.Reflection.MemberInfo.

Exceptions
System.ArgumentException

Can't get the contained type of the given System.Reflection.MemberInfo type.

GetMemberValue(MemberInfo, Object)
Gets the value contained in a given System.Reflection.MemberInfo. Currently only System.Reflection.FieldInfo and System.Reflection.PropertyInfo is supported.
public static object GetMemberValue(MemberInfo member, object obj)
Parameters
System.Reflection.MemberInfo member

The System.Reflection.MemberInfo to get the value of.

System.Object obj

The instance to get the value from.

Returns
System.Object

The value contained in the given System.Reflection.MemberInfo.

Exceptions
System.ArgumentException

Can't get the value of the given System.Reflection.MemberInfo type.

GetSerializableMembers(Type, ISerializationPolicy)
Gets an array of all serializable members on the given type.
public static MemberInfo[] GetSerializableMembers(Type type, ISerializationPolicy policy)
Parameters
System.Type type

The type to get serializable members for.

Sirenix.Serialization.ISerializationPolicy policy

The serialization policy to use. If null, Strict is used.

Returns
System.Reflection.MemberInfo[]

An array of all serializable members on the given type.

GetSerializableMembersMap(Type, ISerializationPolicy)
Gets a map of all serializable members on the given type. This will also properly map names extracted from UnityEngine.Serialization.FormerlySerializedAsAttribute and PreviouslySerializedAsAttribute to their corresponding members.
public static Dictionary<string, MemberInfo> GetSerializableMembersMap(Type type, ISerializationPolicy policy)
Parameters
System.Type type

The type to get a map for.

Sirenix.Serialization.ISerializationPolicy policy

The serialization policy to use. If null, Strict is used.

Returns
System.Collections.Generic.Dictionary<System.String, System.Reflection.MemberInfo>

A map of all serializable members on the given type.

IsPrimitiveArrayType(Type)
Determines whether a given type is a primitive array type. Namely, arrays with primitive array types as elements are primitive arrays.

The following types are primitive array types: System.Char, System.SByte, System.Int16, System.Int32, System.Int64, System.Byte, System.UInt16, System.UInt32, System.UInt64, System.Decimal, System.Boolean, System.Single, System.Double and System.Guid.

public static bool IsPrimitiveArrayType(Type type)
Parameters
System.Type type

The type to check.

Returns
System.Boolean

true if the given type is a primitive array type; otherwise, false.

IsPrimitiveType(Type)
Determines whether a given type is a primitive type to the serialization system.

The following criteria are checked: type.IsPrimitive or type.IsEnum, or type is a System.Decimal, System.String or System.Guid.

public static bool IsPrimitiveType(Type type)
Parameters
System.Type type

The type to check.

Returns
System.Boolean

true if the given type is a primitive type; otherwise, false.

SetMemberValue(MemberInfo, Object, Object)
Sets the value of a given MemberInfo. Currently only System.Reflection.FieldInfo and System.Reflection.PropertyInfo is supported.
public static void SetMemberValue(MemberInfo member, object obj, object value)
Parameters
System.Reflection.MemberInfo member

The System.Reflection.MemberInfo to set the value of.

System.Object obj

The object to set the value on.

System.Object value

The value to set.

Exceptions
System.ArgumentException

Property has no setter or Can't set the value of the given System.Reflection.MemberInfo type.