Skip to content

Extensions

Greg G edited this page Dec 29, 2016 · 1 revision

The blur extension methods provide utils mainly related to Mono.Cecil.

Blur namespace

This namespace provides multiple static classes that provide extension methods that I judge extremely useful.

*Info AsInfo(this *Reference reference)

Converts a Mono.Cecil.*Reference to a System.Reflection.*Info. Example: FieldReference to FieldInfo.

*Reference GetReference(this *Info info)

Converts a System.Reflection.*Info to a Mono.Cecil.*Reference. Example: FieldInfo to FieldReference.

*Definition GetDefinition(this *Info info)

Converts a System.Reflection.*Info to a Mono.Cecil.*Definition. Example: FieldInfo to FieldDefinition.

void Emit(this Instruction ins, ILGenerator il)

Emits a Mono.Cecil.Cil.Instruction to a System.Reflection.Emit.ILGenerator.

Instruction Clone(this Instruction ins)

Clones an Instruction to a new Instruction.
Warning: This method does not clone reference operands, such as Instruction and Instruction[].

object InvokeDefinition(this MethodDefinition method, object obj, params object[] arguments)

WIP: This method should theoretically work, but doesn't. Huh.

Blur.Extensions namespace

This namespace provides static classes that provide extension methods on every object, and a lot of extension methods on ILWriter. Since they add so many methods and may prove themselves useless to many users, they are in a different namespace.

ILWriterExtensions

This static class provides ILWriter methods for every single .NET CIL operation, including a short description, and typed parameters.

FindExtensions

This static class provides a few methods made to use LINQ expressions to easily get an object's field reference, for example. Available methods are:

  • MethodDefinition FindMethod<T>(this T obj, string name, params Type[] parameterTypes)
  • FieldDefinition FindField<T>(this T obj, Expression<Func<T, object>> expr)
  • PropertyDefinition FindProperty<T>(this T obj, Expression<Func<T, object>> expr)
  • EventDefinition FindEvent<T>(this T obj, Expression<Func<T, object>> expr)
Example
this.FindProperty(x => x.Name); // => PropertyDefinition