CodeConstructor GetConstructor()
{
CodeConstructor constructor = new CodeConstructor();
constructor.Attributes = MemberAttributes.Public;
constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(MigrationContext), "context"));
CodeDelegateCreateExpression createDelegate = new CodeDelegateCreateExpression(
new CodeTypeReference("System.EventHandler"),
new CodeThisReferenceExpression(),
EventHandlerName
);
// context.AfterDeserialization += new System.EventHandler(this.<EventHandlerName>);
constructor.Statements.Add(
new CodeAttachEventStatement(
new CodeArgumentReferenceExpression("context"),
"AfterDeserialization",
createDelegate
)
);
return constructor;
}