Exemple #1
0
        public void TestAlgorithmCountMult()
        {
            var proxyMethod = new ProxyMethod(new JacobiMethod());

            loggingSolver     = new LoggingSolver(proxyMethod, Logger);
            double[,] _matrix = new double[3, 3] {
                { 3, 1, 1 },
                { 0, 5, 1 },
                { 2, 0, 3 }
            };

            IVector resultActual = new Vector(new double[] { 1, 1, 1 });

            DenseMatrix denseMatrix = new DenseMatrix(_matrix);
            ProxyMatrix proxyMatrix = new ProxyMatrix(denseMatrix);

            Vector  x0 = new Vector(new double[] { 0, 0, 0 });
            IVector b  = denseMatrix.Multiply(resultActual);

            var result    = loggingSolver.Solve(proxyMatrix, x0, b);
            var MultCount = proxyMethod.MultCount;


            _testOutputHelper.WriteLine(MultCount[0].ToString());
            _testOutputHelper.WriteLine(MultCount[1].ToString());

            for (int i = 0; i < resultActual.Size; i++)
            {
                Assert.Equal(result[i], resultActual[i], 8);
            }
        }
        public void Proxy_methods_inherit_ispublic__name__parameters__return_type_and_custom_attributes_from_given_method()
        {
            //[SecuritySafeCritical] string Insert(int startIndex, string value)
            IMethod real  = type.of <string>().GetMethod("Insert");
            IMethod proxy = new ProxyMethod(type.of <string>(), real);

            Assert.AreEqual(real.IsPublic, proxy.IsPublic);
            Assert.AreEqual(real.Name, proxy.Name);

            Assert.AreEqual(real.Parameters.Count, proxy.Parameters.Count);
            for (int i = 0; i < real.Parameters.Count; i++)
            {
                Assert.AreEqual(real.Parameters[i].Name, proxy.Parameters[i].Name);
                Assert.AreEqual(real.Parameters[i].Index, proxy.Parameters[i].Index);
                Assert.AreEqual(real.Parameters[i].ParameterType, proxy.Parameters[i].ParameterType);
            }

            Assert.AreEqual(real.ReturnType, proxy.ReturnType);

            Assert.AreEqual(real.GetCustomAttributes().Length, proxy.GetCustomAttributes().Length);
            for (int i = 0; i < real.GetCustomAttributes().Length; i++)
            {
                var realAttr  = real.GetCustomAttributes()[i];
                var proxyAttr = proxy.GetCustomAttributes()[i];

                Assert.AreEqual(realAttr, proxyAttr);
            }
        }
        public void Delegates_perform_action_to_the_target_obtained_via_target_delegate()
        {
            IMethod real  = type.of <string>().GetMethod("Insert");
            IMethod proxy = new ProxyMethod(type.of <char>(), real, (o, _) => o.ToString());

            Assert.AreEqual("insertt", proxy.PerformOn('t', 0, "insert"));
        }
        public new ExecutionInfo LoadReport(string Report, string HistoryID)
        {
            ProxyMethod <ExecutionInfo> sql16Method  = new ProxyMethod <ExecutionInfo>("LoadReport3", () => LoadReport3(Report, HistoryID));
            ProxyMethod <ExecutionInfo> katmaiMethod = new ProxyMethod <ExecutionInfo>("LoadReport2", () => LoadReport2(Report, HistoryID));
            ProxyMethod <ExecutionInfo> yukonMethod  = new ProxyMethod <ExecutionInfo>("LoadReport", () => base.LoadReport(Report, HistoryID));

            return(ProxyMethodInvocation.Execute(this, sql16Method, katmaiMethod, yukonMethod));
        }
        public new ExecutionInfo LoadDrillthroughTarget(string DrillthroughID)
        {
            ProxyMethod <ExecutionInfo> sql16Method  = new ProxyMethod <ExecutionInfo>("LoadDrillthroughTarget3", () => LoadDrillthroughTarget3(DrillthroughID));
            ProxyMethod <ExecutionInfo> katmaiMethod = new ProxyMethod <ExecutionInfo>("LoadDrillthroughTarget2", () => LoadDrillthroughTarget2(DrillthroughID));
            ProxyMethod <ExecutionInfo> yukonMethod  = new ProxyMethod <ExecutionInfo>("LoadDrillthroughTarget", () => base.LoadDrillthroughTarget(DrillthroughID));

            return(ProxyMethodInvocation.Execute(this, sql16Method, katmaiMethod, yukonMethod));
        }
        public new ExecutionInfo SetExecutionCredentials(DataSourceCredentials[] Credentials)
        {
            ProxyMethod <ExecutionInfo> sql16Method  = new ProxyMethod <ExecutionInfo>("SetExecutionCredentials3", () => SetExecutionCredentials3(Credentials));
            ProxyMethod <ExecutionInfo> katmaiMethod = new ProxyMethod <ExecutionInfo>("SetExecutionCredentials2", () => SetExecutionCredentials2(Credentials));
            ProxyMethod <ExecutionInfo> yukonMethod  = new ProxyMethod <ExecutionInfo>("SetExecutionCredentials", () => base.SetExecutionCredentials(Credentials));

            return(ProxyMethodInvocation.Execute(this, sql16Method, katmaiMethod, yukonMethod));
        }
        public new ExecutionInfo SetExecutionParameters(ParameterValue[] Parameters, string ParameterLanguage)
        {
            ProxyMethod <ExecutionInfo> sql16Method  = new ProxyMethod <ExecutionInfo>("SetExecutionParameters3", () => SetExecutionParameters3(Parameters, ParameterLanguage));
            ProxyMethod <ExecutionInfo> katmaiMethod = new ProxyMethod <ExecutionInfo>("SetExecutionParameters2", () => SetExecutionParameters2(Parameters, ParameterLanguage));
            ProxyMethod <ExecutionInfo> yukonMethod  = new ProxyMethod <ExecutionInfo>("SetExecutionParameters", () => base.SetExecutionParameters(Parameters, ParameterLanguage));

            return(ProxyMethodInvocation.Execute(this, sql16Method, katmaiMethod, yukonMethod));
        }
        public new ExecutionInfo ResetExecution()
        {
            ProxyMethod <ExecutionInfo> sql16Method  = new ProxyMethod <ExecutionInfo>("ResetExecution3", () => ResetExecution3());
            ProxyMethod <ExecutionInfo> katmaiMethod = new ProxyMethod <ExecutionInfo>("ResetExecution2", () => ResetExecution2());
            ProxyMethod <ExecutionInfo> yukonMethod  = new ProxyMethod <ExecutionInfo>("ResetExecution", () => base.ResetExecution());

            return(ProxyMethodInvocation.Execute(this, sql16Method, katmaiMethod, yukonMethod));
        }
        public void Delegates_perform_action_to_target()
        {
            //[SecuritySafeCritical] string Insert(int startIndex, string value)
            IMethod real  = type.of <string>().GetMethod("Insert");
            IMethod proxy = new ProxyMethod(type.of <string>(), real);

            Assert.AreEqual("inserttest", proxy.PerformOn("test", 0, "insert"));
        }
        public new ExecutionInfo GetExecutionInfo()
        {
            ProxyMethod <ExecutionInfo> sql16Method  = new ProxyMethod <ExecutionInfo>("GetExecutionInfo3", () => GetExecutionInfo3());
            ProxyMethod <ExecutionInfo> katmaiMethod = new ProxyMethod <ExecutionInfo>("GetExecutionInfo2", () => GetExecutionInfo2());
            ProxyMethod <ExecutionInfo> yukonMethod  = new ProxyMethod <ExecutionInfo>("GetExecutionInfo", () => base.GetExecutionInfo());

            return(ProxyMethodInvocation.Execute(this, sql16Method, katmaiMethod, yukonMethod));
        }
        public void Proxy_method_name_can_be_altered()
        {
            //[SecuritySafeCritical] string Insert(int startIndex, string value)
            IMethod real  = type.of <string>().GetMethod("Insert");
            IMethod proxy = new ProxyMethod(type.of <string>(), real).Name.Set("Overridden");

            Assert.AreEqual("Overridden", proxy.Name);
        }
        public new int NavigateBookmark(string BookmarkID, out string UniqueName)
        {
            string            name   = null;
            ProxyMethod <int> method = new ProxyMethod <int>("NavigateBookmark", () => base.NavigateBookmark(BookmarkID, out name));
            int result = ProxyMethodInvocation.Execute(this, method);

            UniqueName = name;
            return(result);
        }
        public void Parent_type_is_what_is_given_as_parent_type()
        {
            var     typeMock = new Mock <IType>();
            var     expected = typeMock.Object;
            IMethod real     = type.of <string>().GetMethod("Insert");
            IMethod proxy    = new ProxyMethod(expected, real);

            Assert.AreSame(expected, proxy.ParentType);
        }
        public void Target_can_be_obtained_from_an_additional_parameter()
        {
            var parameterMock = new Mock <IParameter>();

            IMethod real  = type.of <string>().GetMethod("Insert");
            IMethod proxy = new ProxyMethod(type.of <char>(), real, (_, p) => p[0], parameterMock.Object);

            Assert.AreEqual("inserttest", proxy.PerformOn('t', "test", 0, "insert"));
        }
        public void When_performing_on_real__additional_parameters_are_skipped()
        {
            var parameterMock = new Mock <IParameter>();

            IMethod real  = type.of <string>().GetMethod("Insert");
            IMethod proxy = new ProxyMethod(type.of <char>(), real, (o, _) => o.ToString(), parameterMock.Object);

            Assert.AreEqual("insertt", proxy.PerformOn('t', "dummy", 0, "insert"));
        }
        public new byte[] GetRenderResource(string Format, string DeviceInfo, out string MimeType)
        {
            string mimeType             = null;
            ProxyMethod <byte[]> method = new ProxyMethod <byte[]>("GetRenderResource", () => base.GetRenderResource(Format, DeviceInfo, out mimeType));

            byte[] result = ProxyMethodInvocation.Execute(this, method);
            MimeType = mimeType;
            return(result);
        }
 internal static TReturn Execute <TReturn>(RSExecutionConnection connection, ProxyMethod <TReturn> initialMethod, ProxyMethod <TReturn> retryMethod)
 {
     using (MonitoredScope.NewConcat("ProxyMethodInvocation.Execute - Method : ", initialMethod.MethodName))
     {
         if (connection == null)
         {
             throw new ArgumentNullException("connection");
         }
         if (initialMethod == null)
         {
             throw new ArgumentNullException("initialMethod");
         }
         ProxyMethod <TReturn>[] array = (retryMethod != null && !connection.CanUseKatmaiMethods) ? new ProxyMethod <TReturn>[1]
         {
             retryMethod
         } : ((retryMethod != null) ? new ProxyMethod <TReturn>[2]
         {
             initialMethod,
             retryMethod
         } : new ProxyMethod <TReturn>[1]
         {
             initialMethod
         });
         for (int i = 0; i < array.Length; i++)
         {
             ProxyMethod <TReturn> proxyMethod = array[i];
             try
             {
                 if (!string.IsNullOrEmpty(proxyMethod.MethodName))
                 {
                     connection.SetConnectionSSLForMethod(proxyMethod.MethodName);
                 }
                 return(proxyMethod.Method());
             }
             catch (FaultException e)
             {
                 if (i < array.Length - 1 && connection.CheckForDownlevelRetry(e))
                 {
                     connection.MarkAsFailedUsingKatmai();
                     continue;
                 }
                 connection.OnSoapException(e);
                 throw;
             }
             catch (WebException e2)
             {
                 MissingEndpointException.ThrowIfEndpointMissing(e2);
                 throw;
             }
             catch (InvalidOperationException inner)
             {
                 throw new MissingEndpointException(inner);
             }
         }
         throw new InvalidOperationException("Failed to execute method");
     }
 }
        public void Declaring_type_is_always_the_given_parent_type()
        {
            var     typeMock = new Mock <IType>();
            var     expected = typeMock.Object;
            IMethod real     = type.of <string>().GetMethod("Insert");
            IMethod proxy    = new ProxyMethod(expected, real);

            Assert.AreSame(expected, proxy.GetDeclaringType(false));
            Assert.AreSame(expected, proxy.GetDeclaringType(true));
        }
        public new void LogonUser(string userName, string password, string authority)
        {
            ProxyMethod <int> method = new ProxyMethod <int>(null, delegate
            {
                base.LogonUser(userName, password, authority);
                return(0);
            });

            ProxyMethodInvocation.Execute(this, method);
        }
        public new void Logoff()
        {
            ProxyMethod <int> method = new ProxyMethod <int>("Logoff", delegate
            {
                base.Logoff();
                return(0);
            });

            ProxyMethodInvocation.Execute(this, method);
        }
        public new void DeliverReportItem(string Format, string DeviceInfo, ExtensionSettings ExtensionSettings, string Description, string EventType, string MatchData)
        {
            ProxyMethod <int> method = new ProxyMethod <int>("DeliverReportItem", delegate
            {
                base.DeliverReportItem(Format, DeviceInfo, ExtensionSettings, Description, EventType, MatchData);
                return(0);
            });

            ProxyMethodInvocation.Execute(this, method);
        }
        public new byte[] RenderStream(string Format, string StreamID, string DeviceInfo, out string Encoding, out string MimeType)
        {
            string enc  = null;
            string mime = null;
            ProxyMethod <byte[]> method = new ProxyMethod <byte[]>("RenderStream", () => base.RenderStream(Format, StreamID, DeviceInfo, out enc, out mime));

            byte[] result = ProxyMethodInvocation.Execute(this, method);
            Encoding = enc;
            MimeType = mime;
            return(result);
        }
        public new ExecutionInfo LoadReportDefinition(byte[] Definition, out Warning[] warnings)
        {
            Warning[] w = null;
            ProxyMethod <ExecutionInfo> sql16Method  = new ProxyMethod <ExecutionInfo>("LoadReportDefinition3", () => LoadReportDefinition3(Definition, out w));
            ProxyMethod <ExecutionInfo> katmaiMethod = new ProxyMethod <ExecutionInfo>("LoadReportDefinition2", () => LoadReportDefinition2(Definition, out w));
            ProxyMethod <ExecutionInfo> yukonMethod  = new ProxyMethod <ExecutionInfo>("LoadReportDefinition", () => base.LoadReportDefinition(Definition, out w));
            ExecutionInfo result = ProxyMethodInvocation.Execute(this, sql16Method, katmaiMethod, yukonMethod);

            warnings = w;
            return(result);
        }
        public new int Sort(string SortItem, SortDirectionEnum Direction, bool Clear, out string ReportItem, out int NumPages)
        {
            string            rptItem = null;
            int               nPages  = 0;
            ProxyMethod <int> method  = new ProxyMethod <int>("Sort", () => base.Sort(SortItem, Direction, Clear, out rptItem, out nPages));
            int               result  = ProxyMethodInvocation.Execute(this, method);

            ReportItem = rptItem;
            NumPages   = nPages;
            return(result);
        }
Exemple #25
0
        /// <summary>
        /// Used on methods to instrut that a certain set of parameter data
        /// should not throw a specified exception.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="N"></typeparam>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static T NotRaise <T, N>(this T obj, N value)
        {
            ProxyTrace  trace      = GetTrace();
            ProxyMethod methodCall = trace.MethodCalls.Last();

            if (methodCall.Ex == null)
            {
                return(obj);
            }

            throw new CSpecException(ExceptionMessages.Key + " @not_raise");
        }
Exemple #26
0
            public InterfaceBuilder(Type tInterface)
            {
                this.tInterface = tInterface;
                methods         = tInterface.getMethodsWithoutProperties().ToArray();
                Type[] tDelegates = NativeDelegates.buildDelegates(tInterface);
                Debug.Assert(methods.Length == tDelegates.Length);
                prefabs = new iMethodPrefab[methods.Length];

                var conventions = tInterface.GetCustomAttribute <CustomConventionsAttribute>();

                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo mi = methods[i];
                    // Check if any C# arguments need custom marshallers
                    bool anyCustom = mi.GetParameters().Any(Marshallers.hasCustomMarshaller);
                    // If the method has [RetValIndex], it also counts.
                    if (mi.hasRetValIndex())
                    {
                        anyCustom = true;
                    }

                    if (anyCustom)
                    {
                        try
                        {
                            prefabs[i] = new CustomMarshallerMethod(mi, tDelegates[i], i, conventions);
                        }
                        catch (Exception ex)
                        {
                            throw new SerializationException($"Error building custom callable proxy method {tInterface.FullName}.{mi.Name}", ex);
                        }
                    }
                    else
                    {
                        try
                        {
                            prefabs[i] = new ProxyMethod(mi, tDelegates[i]);
                        }
                        catch (Exception ex)
                        {
                            throw new SerializationException($"Error building callable proxy method {tInterface.FullName}.{mi.Name}", ex);
                        }
                    }
                }
            }
        public byte[] Render(string Format, string DeviceInfo, PageCountMode PaginationMode, out string Extension, out string MimeType, out string Encoding, out Warning[] Warnings, out string[] StreamIds)
        {
            string ext  = null;
            string mime = null;
            string enc  = null;

            Warning[]            w             = null;
            string[]             sids          = null;
            ProxyMethod <byte[]> initialMethod = new ProxyMethod <byte[]>("Render2", () => Render2(Format, DeviceInfo, PaginationMode, out ext, out mime, out enc, out w, out sids));
            ProxyMethod <byte[]> retryMethod   = new ProxyMethod <byte[]>("Render", () => base.Render(Format, DeviceInfo, out ext, out mime, out enc, out w, out sids));

            byte[] result = ProxyMethodInvocation.Execute(this, initialMethod, retryMethod);
            Extension = ext;
            MimeType  = mime;
            Encoding  = enc;
            Warnings  = w;
            StreamIds = sids;
            return(result);
        }
        public void Additional_parameter_shifts_index_of_the_real_parameters()
        {
            var parameterMock = new Mock <IParameter>();

            parameterMock.Setup(o => o.Name).Returns("additional");
            parameterMock.Setup(o => o.ParameterType).Returns(type.of <string>());

            IMethod real  = type.of <string>().GetMethod("Insert");
            IMethod proxy = new ProxyMethod(type.of <char>(), real, (o, _) => o.ToString(), parameterMock.Object);

            Assert.AreEqual(real.Parameters.Count + 1, proxy.Parameters.Count);
            Assert.AreEqual("additional", proxy.Parameters[0].Name);
            Assert.AreEqual(0, proxy.Parameters[0].Index);
            Assert.AreEqual(type.of <string>(), proxy.Parameters[0].ParameterType);
            for (int i = 0; i < real.Parameters.Count; i++)
            {
                Assert.AreEqual(real.Parameters[i].Name, proxy.Parameters[i + 1].Name);
                Assert.AreEqual(real.Parameters[i].Index + 1, proxy.Parameters[i + 1].Index);
                Assert.AreEqual(real.Parameters[i].ParameterType, proxy.Parameters[i + 1].ParameterType);
            }
        }
Exemple #29
0
            public InterfaceBuilder(Type tInterface)
            {
                this.tInterface = tInterface;
                methods         = tInterface.GetMethods();
                Type[] tDelegates = NativeDelegates.buildDelegates(tInterface);
                Debug.Assert(methods.Length == tDelegates.Length);
                prefabs = new iMethodPrefab[methods.Length];

                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo mi        = methods[i];
                    bool       anyCustom = mi.GetParameters().Any(Marshallers.hasCustomMarshaller);
                    if (anyCustom)
                    {
                        prefabs[i] = new CustomMarshallerMethod(mi, tDelegates[i], i);
                    }
                    else
                    {
                        prefabs[i] = new ProxyMethod(mi, tDelegates[i]);
                    }
                }
            }
        public int Sort(string SortItem, SortDirectionEnum Direction, bool Clear, PageCountMode PaginationMode, out string ReportItem, out ExecutionInfo ExecutionInfo, out int NumPages)
        {
            string            rptItem       = null;
            int               nPages        = 0;
            ExecutionInfo2    execInfo      = null;
            ProxyMethod <int> initialMethod = new ProxyMethod <int>("Sort2", delegate
            {
                int result2 = Sort2(SortItem, Direction, Clear, PaginationMode, out rptItem, out execInfo);
                if (execInfo != null)
                {
                    nPages = execInfo.NumPages;
                }
                return(result2);
            });
            ProxyMethod <int> retryMethod = new ProxyMethod <int>("Sort", () => base.Sort(SortItem, Direction, Clear, out rptItem, out nPages));
            int result = ProxyMethodInvocation.Execute(this, initialMethod, retryMethod);

            ExecutionInfo = execInfo;
            NumPages      = nPages;
            ReportItem    = rptItem;
            return(result);
        }
		private static void CreateMethod(CompilerClassLoader loader, TypeBuilder tb, ProxyMethod pm)
		{
			MethodBuilder mb = pm.mw.GetDefineMethodHelper().DefineMethod(loader.GetTypeWrapperFactory(), tb, pm.mw.Name, MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final);
			List<string> exceptions = new List<string>();
			foreach (TypeWrapper tw in pm.exceptions)
			{
				exceptions.Add(tw.Name);
			}
			AttributeHelper.SetThrowsAttribute(mb, exceptions.ToArray());
			CodeEmitter ilgen = CodeEmitter.Create(mb);
			ilgen.BeginExceptionBlock();
			ilgen.Emit(OpCodes.Ldarg_0);
			invocationHandlerField.EmitGet(ilgen);
			ilgen.Emit(OpCodes.Ldarg_0);
			ilgen.Emit(OpCodes.Ldsfld, pm.fb);
			TypeWrapper[] parameters = pm.mw.GetParameters();
			if (parameters.Length == 0)
			{
				ilgen.Emit(OpCodes.Ldnull);
			}
			else
			{
				ilgen.Emit_Ldc_I4(parameters.Length);
				ilgen.Emit(OpCodes.Newarr, Types.Object);
				for (int i = 0; i < parameters.Length; i++)
				{
					ilgen.Emit(OpCodes.Dup);
					ilgen.Emit_Ldc_I4(i);
					ilgen.Emit(OpCodes.Ldarg, (short)i);
					if (parameters[i].IsNonPrimitiveValueType)
					{
						parameters[i].EmitBox(ilgen);
					}
					else if (parameters[i].IsPrimitive)
					{
						Boxer.EmitBox(ilgen, parameters[i]);
					}
					ilgen.Emit(OpCodes.Stelem_Ref);
				}
			}
			invokeMethod.EmitCallvirt(ilgen);
			TypeWrapper returnType = pm.mw.ReturnType;
			CodeEmitterLocal returnValue = null;
			if (returnType != PrimitiveTypeWrapper.VOID)
			{
				returnValue = ilgen.DeclareLocal(returnType.TypeAsSignatureType);
				if (returnType.IsNonPrimitiveValueType)
				{
					returnType.EmitUnbox(ilgen);
				}
				else if (returnType.IsPrimitive)
				{
					Boxer.EmitUnbox(ilgen, returnType);
				}
				else if (returnType != CoreClasses.java.lang.Object.Wrapper)
				{
					ilgen.EmitCastclass(returnType.TypeAsSignatureType);
				}
				ilgen.Emit(OpCodes.Stloc, returnValue);
			}
			CodeEmitterLabel returnLabel = ilgen.DefineLabel();
			ilgen.Emit(OpCodes.Leave, returnLabel);
			// TODO consider using a filter here (but we would need to add filter support to CodeEmitter)
			ilgen.BeginCatchBlock(Types.Exception);
			ilgen.Emit_Ldc_I4(0);
			ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.mapException.MakeGenericMethod(Types.Exception));
			CodeEmitterLocal exception = ilgen.DeclareLocal(Types.Exception);
			ilgen.Emit(OpCodes.Stloc, exception);
			CodeEmitterLabel rethrow = ilgen.DefineLabel();
			ilgen.Emit(OpCodes.Ldloc, exception);
			errorClass.EmitInstanceOf(null, ilgen);
			ilgen.Emit(OpCodes.Brtrue, rethrow);
			ilgen.Emit(OpCodes.Ldloc, exception);
			runtimeExceptionClass.EmitInstanceOf(null, ilgen);
			ilgen.Emit(OpCodes.Brtrue, rethrow);
			foreach (TypeWrapper tw in pm.exceptions)
			{
				ilgen.Emit(OpCodes.Ldloc, exception);
				tw.EmitInstanceOf(null, ilgen);
				ilgen.Emit(OpCodes.Brtrue, rethrow);
			}
			ilgen.Emit(OpCodes.Ldloc, exception);
			undeclaredThrowableExceptionConstructor.EmitNewobj(ilgen);
			ilgen.Emit(OpCodes.Throw);
			ilgen.MarkLabel(rethrow);
			ilgen.Emit(OpCodes.Rethrow);
			ilgen.EndExceptionBlock();
			ilgen.MarkLabel(returnLabel);
			if (returnValue != null)
			{
				ilgen.Emit(OpCodes.Ldloc, returnValue);
			}
			ilgen.Emit(OpCodes.Ret);
			ilgen.DoEmit();
		}
Exemple #32
0
    /// <summary>
    /// Create a proxy method implementing the abstractMethod and which calls the implementingMethod.
    /// This is needed when the implementingMethod is supposed to be used for the implementation
    /// of the abstractMethod, but cannot be because it lives in another assembly or isn't virtual
    /// or the abstractMethod has an out-of-band contract and the implementingMethod must have
    /// an identical type signature (i.e., no optional type modifiers for the non-null types).
    /// </summary>
    /// <param name="type">The type containing the implementingMethod and to which the
    /// proxy will be added as a member.</param>
    /// <param name="abstractMethod">The abstract method that the proxy is an implementation of.</param>
    /// <param name="implementingMethod">The implementing method that is supposed to implement
    /// the abstractMethod, but is unable to for various reasons.</param>
    /// <returns>The newly created proxy method.</returns>
    private Method CreateProxy(TypeNode type, Method abstractMethod, Method implementingMethod) {
      ParameterList parameters = abstractMethod.Parameters;
      if (parameters == null)
        parameters = new ParameterList(0);
      else
        parameters = parameters.Clone();
      int m = parameters.Count;
      ExpressionList arguments = new ExpressionList(m);
      for (int j = 0; j < m; j++) {
        Parameter p = (Parameter)parameters[j].Clone();
        parameters[j] = p;
        if (this.typeSystem.IsNonNullType(p.Type)) {
          arguments.Add(this.typeSystem.ExplicitNonNullCoercion(p, p.Type));
        } else {
          arguments.Add(p);
        }
        p.Type = TypeNode.DeepStripModifiers(p.Type, (abstractMethod.Template!=null)?abstractMethod.Template.Parameters[j].Type:null, SystemTypes.NonNullType);
      }
      This ThisParameter = new This(this.currentType);
      StatementList statements = new StatementList(2);
      NodeType typeOfCall = type.IsValueType ? NodeType.Call : NodeType.Callvirt;
      MethodCall mCall = new MethodCall(new MemberBinding(ThisParameter, implementingMethod), arguments, typeOfCall, implementingMethod.ReturnType);
      if (implementingMethod.ReturnType != SystemTypes.Void) {
        statements.Add(new Return(mCall));
      } else {
        statements.Add(new ExpressionStatement(mCall));
        statements.Add(new Return());
      }
      TypeNode returnType = TypeNode.DeepStripModifiers(abstractMethod.ReturnType, (abstractMethod.Template != null) ? abstractMethod.Template.ReturnType : null, SystemTypes.NonNullType);
      ProxyMethod proxy = new ProxyMethod(type, null, new Identifier(abstractMethod.DeclaringType.Name + "." + abstractMethod.Name, implementingMethod.Name.SourceContext), parameters, returnType, new Block(statements));
      proxy.ProxyFor = implementingMethod;
      proxy.ThisParameter = ThisParameter;
      proxy.CallingConvention = CallingConventionFlags.HasThis;

      proxy.Flags = MethodFlags.CompilerControlled | MethodFlags.HideBySig | MethodFlags.NewSlot | MethodFlags.Virtual | MethodFlags.Final;
      proxy.ImplementedInterfaceMethods = new MethodList(abstractMethod);
      type.Members.Add(proxy);
      return proxy;
    }