Version 2.1.0.0

EmitUtilities class

Namespace: Sirenix.Utilities
Assembly: Sirenix.Utilities
public static class EmitUtilities
Provides utilities for using the System.Reflection.Emit namespace.

This class is due for refactoring. Use at your own peril.

Inheritance
  • System.Object
  • EmitUtilities

Properties

CanEmit
Gets a value indicating whether emitting is supported on the current platform.
public static bool CanEmit { get; }

Methods

CreateInstanceFieldGetter<InstanceType, FieldType>(FieldInfo)
Creates a delegate which gets the value of a field. If emitting is not supported on the current platform, the delegate will use reflection to get the value.
public static ValueGetter<InstanceType, FieldType> CreateInstanceFieldGetter<InstanceType, FieldType>(FieldInfo fieldInfo)
Parameters
System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a getter for.

Returns
Sirenix.Utilities.ValueGetter<InstanceType, FieldType>

A delegate which gets the value of the given field.

Type Parameters
InstanceType

The type of the instance to get a value from.

FieldType

The type of the field to get a value from.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

CreateInstanceFieldSetter<InstanceType, FieldType>(FieldInfo)
Creates a delegate which sets the value of a field. If emitting is not supported on the current platform, the delegate will use reflection to set the value.
public static ValueSetter<InstanceType, FieldType> CreateInstanceFieldSetter<InstanceType, FieldType>(FieldInfo fieldInfo)
Parameters
System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a setter for.

Returns
Sirenix.Utilities.ValueSetter<InstanceType, FieldType>

A delegate which sets the value of the given field.

Type Parameters
InstanceType

The type of the instance to set a value on.

FieldType

The type of the field to set a value to.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

CreateInstanceMethodCaller<InstanceType>(MethodInfo)
Creates a fast delegate method which calls a given parameterless instance method.
public static Action<InstanceType> CreateInstanceMethodCaller<InstanceType>(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

The method info instance which is used.

Returns
System.Action<InstanceType>

A delegate which calls the method and returns the result, except it's hundreds of times faster than MethodInfo.Invoke.

Type Parameters
InstanceType

The type of the class which the method is on.

CreateInstanceMethodCaller<InstanceType, Arg1>(MethodInfo)
Creates a fast delegate method which calls a given instance method with a given argument.
public static Action<InstanceType, Arg1> CreateInstanceMethodCaller<InstanceType, Arg1>(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

The method info instance which is used.

Returns
System.Action<InstanceType, Arg1>

A delegate which calls the method and returns the result, except it's hundreds of times faster than MethodInfo.Invoke.

Type Parameters
InstanceType

The type of the class which the method is on.

Arg1

The type of the argument with which to call the method.

CreateInstancePropertyGetter<InstanceType, PropType>(PropertyInfo)
Creates a delegate which gets the value of a property. If emitting is not supported on the current platform, the delegate will use reflection to get the value.
public static ValueGetter<InstanceType, PropType> CreateInstancePropertyGetter<InstanceType, PropType>(PropertyInfo propertyInfo)
Parameters
System.Reflection.PropertyInfo propertyInfo

The System.Reflection.PropertyInfo instance describing the property to create a getter for.

Returns
Sirenix.Utilities.ValueGetter<InstanceType, PropType>

A delegate which gets the value of the given property.

Type Parameters
InstanceType

The type of the instance to get a value from.

PropType

The type of the property to get a value from.

Exceptions
System.ArgumentNullException

The propertyInfo parameter is null.

CreateInstancePropertySetter<InstanceType, PropType>(PropertyInfo)
Creates a delegate which sets the value of a property. If emitting is not supported on the current platform, the delegate will use reflection to set the value.
public static ValueSetter<InstanceType, PropType> CreateInstancePropertySetter<InstanceType, PropType>(PropertyInfo propertyInfo)
Parameters
System.Reflection.PropertyInfo propertyInfo

The System.Reflection.PropertyInfo instance describing the property to create a setter for.

Returns
Sirenix.Utilities.ValueSetter<InstanceType, PropType>

A delegate which sets the value of the given property.

Type Parameters
InstanceType

The type of the instance to set a value on.

PropType

The type of the property to set a value to.

Exceptions
System.ArgumentNullException

The propertyInfo parameter is null.

CreateMethodReturner<InstanceType, ReturnType>(MethodInfo)
Creates a fast delegate method which calls a given parameterless instance method and returns the result.
public static Func<InstanceType, ReturnType> CreateMethodReturner<InstanceType, ReturnType>(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

The method info instance which is used.

Returns
System.Func<InstanceType, ReturnType>

A delegate which calls the method and returns the result, except it's hundreds of times faster than MethodInfo.Invoke.

Type Parameters
InstanceType

The type of the class which the method is on.

ReturnType

The type which is returned by the given method info.

CreateStaticFieldGetter<FieldType>(FieldInfo)
Creates a delegate which gets the value of a field. If emitting is not supported on the current platform, the delegate will use reflection to get the value.
public static Func<FieldType> CreateStaticFieldGetter<FieldType>(FieldInfo fieldInfo)
Parameters
System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a getter for.

Returns
System.Func<FieldType>

A delegate which gets the value of the given field.

Type Parameters
FieldType

The type of the field to get a value from.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

CreateStaticFieldSetter<FieldType>(FieldInfo)
Creates a delegate which sets the value of a field. If emitting is not supported on the current platform, the delegate will use reflection to set the value.
public static Action<FieldType> CreateStaticFieldSetter<FieldType>(FieldInfo fieldInfo)
Parameters
System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a setter for.

Returns
System.Action<FieldType>

A delegate which sets the value of the given field.

Type Parameters
FieldType

The type of the field to set a value to.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

CreateStaticMethodCaller(MethodInfo)
Creates a fast delegate method which calls a given parameterless static method.
public static Action CreateStaticMethodCaller(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

The method info instance which is used.

Returns
System.Action

A delegate which calls the method and returns the result, except it's hundreds of times faster than MethodInfo.Invoke.

CreateStaticPropertyGetter<PropType>(PropertyInfo)
Creates a delegate which gets the value of a property. If emitting is not supported on the current platform, the delegate will use reflection to get the value.
public static Func<PropType> CreateStaticPropertyGetter<PropType>(PropertyInfo propertyInfo)
Parameters
System.Reflection.PropertyInfo propertyInfo

The System.Reflection.PropertyInfo instance describing the property to create a getter for.

Returns
System.Func<PropType>

A delegate which gets the value of the given property.

Type Parameters
PropType

The type of the property to get a value from.

Exceptions
System.ArgumentNullException

The propertyInfo parameter is null.

CreateStaticPropertySetter<PropType>(PropertyInfo)
Creates a delegate which sets the value of a property. If emitting is not supported on the current platform, the delegate will use reflection to set the value.
public static Action<PropType> CreateStaticPropertySetter<PropType>(PropertyInfo propertyInfo)
Parameters
System.Reflection.PropertyInfo propertyInfo

The System.Reflection.PropertyInfo instance describing the property to create a setter for.

Returns
System.Action<PropType>

A delegate which sets the value of the given property.

Type Parameters
PropType

The type of the property to set a value to.

Exceptions
System.ArgumentNullException

The propertyInfo parameter is null.

CreateWeakInstanceFieldGetter(Type, FieldInfo)
Creates a delegate which gets the weakly typed value of a field from a weakly typed instance of a given type. If emitting is not supported on the current platform, the delegate will use reflection to get the value.
public static WeakValueGetter CreateWeakInstanceFieldGetter(Type instanceType, FieldInfo fieldInfo)
Parameters
System.Type instanceType

The System.Type of the instance to get a value from.

System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a getter for.

Returns
Sirenix.Utilities.WeakValueGetter

A delegate which gets the value of the given field.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

CreateWeakInstanceFieldGetter<FieldType>(Type, FieldInfo)
Creates a delegate which gets the value of a field from a weakly typed instance of a given type. If emitting is not supported on the current platform, the delegate will use reflection to get the value.
public static WeakValueGetter<FieldType> CreateWeakInstanceFieldGetter<FieldType>(Type instanceType, FieldInfo fieldInfo)
Parameters
System.Type instanceType

The System.Type of the instance to get a value from.

System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a getter for.

Returns
Sirenix.Utilities.WeakValueGetter<FieldType>

A delegate which gets the value of the given field.

Type Parameters
FieldType

The type of the field to get a value from.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

CreateWeakInstanceFieldSetter(Type, FieldInfo)
Creates a delegate which sets the weakly typed value of a field on a weakly typed instance of a given type. If emitting is not supported on the current platform, the delegate will use reflection to set the value.
public static WeakValueSetter CreateWeakInstanceFieldSetter(Type instanceType, FieldInfo fieldInfo)
Parameters
System.Type instanceType

Type of the instance.

System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a setter for.

Returns
Sirenix.Utilities.WeakValueSetter

A delegate which sets the value of the given field.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

System.ArgumentException

Field cannot be static.

CreateWeakInstanceFieldSetter<FieldType>(Type, FieldInfo)
Creates a delegate which sets the value of a field on a weakly typed instance of a given type. If emitting is not supported on the current platform, the delegate will use reflection to set the value.
public static WeakValueSetter<FieldType> CreateWeakInstanceFieldSetter<FieldType>(Type instanceType, FieldInfo fieldInfo)
Parameters
System.Type instanceType

Type of the instance.

System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a setter for.

Returns
Sirenix.Utilities.WeakValueSetter<FieldType>

A delegate which sets the value of the given field.

Type Parameters
FieldType

The type of the field to set a value to.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

System.ArgumentException

Field cannot be static.

CreateWeakInstanceMethodCaller(MethodInfo)
Not yet documented.
public static Action<object> CreateWeakInstanceMethodCaller(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

Returns
System.Action<System.Object>

CreateWeakInstanceMethodCaller<TArg1>(MethodInfo)
Creates a fast delegate method which calls a given parameterless weakly typed instance method.
public static Action<object, TArg1> CreateWeakInstanceMethodCaller<TArg1>(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

The method info instance which is used.

Returns
System.Action<System.Object, TArg1>

A delegate which calls the method and returns the result, except it's hundreds of times faster than MethodInfo.Invoke.

Type Parameters
TArg1

CreateWeakInstanceMethodCaller<TResult, TArg1>(MethodInfo)
Creates a fast delegate method which calls a given weakly typed instance method with one argument and returns a value.
public static Func<object, TArg1, TResult> CreateWeakInstanceMethodCaller<TResult, TArg1>(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

The method info instance which is used.

Returns
System.Func<System.Object, TArg1, TResult>

A delegate which calls the method and returns the result, except it's hundreds of times faster than MethodInfo.Invoke.

Type Parameters
TResult

The type of the result.

TArg1

The type of the first argument.

Exceptions
System.ArgumentNullException

methodInfo

System.ArgumentException

Given method ' + methodInfo.Name + ' is static when it has to be an instance method. or Given method ' + methodInfo.Name + ' must return type + typeof(TResult) + . or Given method ' + methodInfo.Name + ' must have exactly one parameter. or The first parameter of the method ' + methodInfo.Name + ' must be of type + typeof(TArg1) + .

CreateWeakInstanceMethodCallerFunc<TResult>(MethodInfo)
Not yet documented.
public static Func<object, TResult> CreateWeakInstanceMethodCallerFunc<TResult>(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

Returns
System.Func<System.Object, TResult>

Type Parameters
TResult

CreateWeakInstanceMethodCallerFunc<TArg, TResult>(MethodInfo)
Not yet documented.
public static Func<object, TArg, TResult> CreateWeakInstanceMethodCallerFunc<TArg, TResult>(MethodInfo methodInfo)
Parameters
System.Reflection.MethodInfo methodInfo

Returns
System.Func<System.Object, TArg, TResult>

Type Parameters
TArg

TResult

CreateWeakInstancePropertyGetter(Type, PropertyInfo)
Creates a delegate which gets the weakly typed value of a field from a weakly typed instance of a given type. If emitting is not supported on the current platform, the delegate will use reflection to get the value.
public static WeakValueGetter CreateWeakInstancePropertyGetter(Type instanceType, PropertyInfo propertyInfo)
Parameters
System.Type instanceType

The System.Type of the instance to get a value from.

System.Reflection.PropertyInfo propertyInfo

The System.Reflection.FieldInfo instance describing the field to create a getter for.

Returns
Sirenix.Utilities.WeakValueGetter

A delegate which gets the value of the given field.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

CreateWeakInstancePropertySetter(Type, PropertyInfo)
Creates a delegate which sets the weakly typed value of a property on a weakly typed instance of a given type. If emitting is not supported on the current platform, the delegate will use reflection to set the value.
public static WeakValueSetter CreateWeakInstancePropertySetter(Type instanceType, PropertyInfo propertyInfo)
Parameters
System.Type instanceType

Type of the instance.

System.Reflection.PropertyInfo propertyInfo

The System.Reflection.PropertyInfo instance describing the property to create a setter for.

Returns
Sirenix.Utilities.WeakValueSetter

A delegate which sets the value of the given field.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

System.ArgumentException

Property cannot be static.

CreateWeakStaticFieldGetter(FieldInfo)
Creates a delegate which gets the value of a field. If emitting is not supported on the current platform, the delegate will use reflection to get the value.
public static Func<object> CreateWeakStaticFieldGetter(FieldInfo fieldInfo)
Parameters
System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a getter for.

Returns
System.Func<System.Object>

A delegate which gets the value of the given field.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.

CreateWeakStaticFieldSetter(FieldInfo)
Creates a delegate which sets the value of a field. If emitting is not supported on the current platform, the delegate will use reflection to set the value.
public static Action<object> CreateWeakStaticFieldSetter(FieldInfo fieldInfo)
Parameters
System.Reflection.FieldInfo fieldInfo

The System.Reflection.FieldInfo instance describing the field to create a setter for.

Returns
System.Action<System.Object>

A delegate which sets the value of the given field.

Exceptions
System.ArgumentNullException

The fieldInfo parameter is null.