private void GenerateProxyMethodInvocation(CodeGenerator codeGen, MethodInfo proxyMethod, Label proxyMethodLabelStart) { var wrapperType = InfoProvider.GetWrapperType <TProxy>(); var getter = wrapperType.GetProperty("ProxyObject").GetGetMethod(); var proxyObject = codeGen.DeclareLocalVariable(typeof(ProxyWrapper <TProxy>)); codeGen.MarkLabel(proxyMethodLabelStart); codeGen.GetProperty(methodGetter: getter, storeVariable: proxyObject); codeGen.InvokeMethodOnObject(proxyObject, proxyMethod); }
private void GenerateAdditionalMethodInvocation(CodeGenerator codeGen, Label exitLabel, string propsName) { var wrapperType = InfoProvider.GetWrapperType <TProxy>(); var preActionGetter = wrapperType.GetProperty(propsName).GetGetMethod(); var preActionVariable = codeGen.DeclareLocalVariable(typeof(Action)); // try block start codeGen.BeginTry(); var preActionNoLabel = codeGen.DefineLabel(); codeGen.GetProperty(methodGetter: preActionGetter, storeVariable: preActionVariable); codeGen.BeginIfNullBlock(variable: preActionVariable, goIfNull: preActionNoLabel); codeGen.InvokeMethodAsVariable(preActionVariable); codeGen.MarkEndIfBlock(preActionNoLabel); codeGen.GoTo(exitLabel); // exit // start catch codeGen.EndTry(); codeGen.BeginCatch(); // codeGen.ReThrowException(); codeGen.EndCatch(); }
public void ImplementConstructor() { var constructorBuilder = _typeBuilder.DefineConstructor( MethodAttributes.Public, CallingConventions.HasThis, new [] { typeof(TProxy) }); var wrapperType = InfoProvider.GetWrapperType <TProxy>(); var baseConstructor = wrapperType.GetConstructor( BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null); var setter = wrapperType.GetProperty("ProxyObject").GetSetMethod(); var ILGen = constructorBuilder.GetILGenerator(); var codeGen = new CodeGenerator(ILGen); codeGen.InitializeBaseCtor(baseConstructor); codeGen.SetPropertyCtor(setter, index: 1); codeGen.Return(); }