internal void BuildMethods() { if (_isInternal || _isBuiltMethods) { return; } _isBuiltMethods = true; using (var injectFromBinding = new InjectFromMemberBindingTree(this, _mappingType, _mappingTypeMember)) { injectFromBinding.Bind(_bindings); DeclareInjectFromMethod(injectFromBinding); } using (var injectToBinding = new InjectToMemberBindingTree(this, _mappingType, _mappingTypeMember)) { injectToBinding.Bind(_bindings); DeclareInjectToMethod(injectToBinding); } DeclareGetPrimaryKeysMethod(); }
private void DeclareInjectFromMethod(InjectFromMemberBindingTree memberBindings) { var attr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; var methodGetBuilder = _typeBuilder.DefineMethod(InjectFromMethodName, attr, null, new[] { _mappingType }); var methodIL = methodGetBuilder.GetILGenerator(); var ret = methodIL.DefineLabel(); var endIf = methodIL.DefineLabel(); methodIL.Emit(OpCodes.Nop); methodIL.Emit(OpCodes.Ldarg_1); methodIL.Emit(OpCodes.Ldnull); methodIL.Emit(OpCodes.Ceq); methodIL.Emit(OpCodes.Brfalse, endIf); methodIL.Emit(OpCodes.Br, ret); methodIL.MarkLabel(endIf); memberBindings.Build(methodIL); methodIL.MarkLabel(ret); methodIL.Emit(OpCodes.Ret); }