public DelegateCaller(MethodDesc method, DelegateWrapperDeclaration container) : base(container, 0) { DelegateDeclaration delegateDeclaration = new DelegateDeclaration(container.Type, container, container.AccessModifier); string returnDecl = MethodDeclaration.GetReturnValue(method); IEnumerable <string> argumentNames = MethodDeclaration.GetParameterNames(method); WriteLine(() => "{"); WriteLine(() => " if (reference == IntPtr.Zero)"); WriteLine(() => " throw new InvalidComObjectException();"); WriteLine(() => " Delegate genericDelegate = Marshal.GetDelegateForFunctionPointer(reference, typeof(" + delegateDeclaration.DelegateTypeName + "));"); WriteLine(() => " " + delegateDeclaration.DelegateTypeName + " method = (" + delegateDeclaration.DelegateTypeName + ")genericDelegate;"); WriteLine(() => " " + ((returnDecl == "void") ? "" : "return ") + "method(" + string.Join(", ", argumentNames) + ");"); WriteLine(() => "}"); }
public DelegateCaller(MethodDesc method, DelegateWrapperDeclaration container) : base(container, 0) { DelegateDeclaration delegateDeclaration = new DelegateDeclaration(container.Type, container, container.AccessModifier); string returnDecl = MethodDeclaration.GetReturnValue(method); IEnumerable<string> argumentNames = MethodDeclaration.GetParameterNames(method); WriteLine(() => "{"); WriteLine(() => " if (reference == IntPtr.Zero)"); WriteLine(() => " throw new InvalidComObjectException();"); WriteLine(() => " Delegate genericDelegate = Marshal.GetDelegateForFunctionPointer(reference, typeof(" + delegateDeclaration.DelegateTypeName + "));"); WriteLine(() => " " + delegateDeclaration.DelegateTypeName + " method = (" + delegateDeclaration.DelegateTypeName + ")genericDelegate;"); WriteLine(() => " " + ((returnDecl == "void") ? "" : "return ") + "method(" + string.Join(", ", argumentNames) + ");"); WriteLine(() => "}"); }