public void CreateDebugClass() { TypeBuilder debugClass = GeneratedAssembly.CreateType(TargetType.Name + "Formatter"); SerializeMethod = debugClass.DefineMethod("Serialize", _staticMethodAttributes, typeof(void), SerializeParams.Types); SerializeExpression.CompileToMethod(SerializeMethod); DeserializeMethod = debugClass.DefineMethod("Deserialize", _staticMethodAttributes, TargetType, DeserializeParams.Types); DeserializeExpression.CompileToMethod(DeserializeMethod); ShouldSkipMethod = debugClass.DefineMethod("ShouldSkip", _staticMethodAttributes, typeof(bool), new Type[] { TargetType }); ShouldSkipExpression.CompileToMethod(ShouldSkipMethod); debugClass.CreateType(); }
public IFormatter BuildFormatter() { Initialize(); CreateSerializeMethod(); CreateDeserializeMethod(); CreateShouldSkipMethod(); IEditableFormatter editableFormatter = Activator.CreateInstance(typeof(EditableFormatter <>).MakeGenericType(TargetType)) as IEditableFormatter; editableFormatter.DeserializationDelegate = DeserializeExpression.Compile(); editableFormatter.SerializationDelegate = SerializeExpression.Compile(); editableFormatter.ShouldSkipFieldDelegate = ShouldSkipExpression.Compile(); CreateDebugClass(); return(editableFormatter as IFormatter); }