當前位置: 首頁>>代碼示例>>C#>>正文


C# CilWorker.PushGenericArguments方法代碼示例

本文整理匯總了C#中Mono.Cecil.Cil.CilWorker.PushGenericArguments方法的典型用法代碼示例。如果您正苦於以下問題:C# CilWorker.PushGenericArguments方法的具體用法?C# CilWorker.PushGenericArguments怎麽用?C# CilWorker.PushGenericArguments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.Cil.CilWorker的用法示例。


在下文中一共展示了CilWorker.PushGenericArguments方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SaveInvocationInfo

        private void SaveInvocationInfo(CilWorker IL, MethodReference targetMethod, ModuleDefinition module, TypeReference returnType)
        {
            // If the target method is an instance method, then the remaining item on the stack
            // will be the target object instance

            // Put all the method arguments into the argument stack
            foreach (ParameterReference param in targetMethod.Parameters)
            {
                // Save the current argument
                var parameterType = param.ParameterType;
                if (parameterType.IsValueType || parameterType is GenericParameter)
                    IL.Emit(OpCodes.Box, parameterType);

                IL.Emit(OpCodes.Stloc, _currentArgument);
                IL.Emit(OpCodes.Ldloc, _currentArguments);
                IL.Emit(OpCodes.Ldloc, _currentArgument);
                IL.Emit(OpCodes.Callvirt, _pushMethod);
            }

            // Static methods will always have a null reference as the target
            if (!targetMethod.HasThis)
                IL.Emit(OpCodes.Ldnull);

            // Box the target, if necessary
            var declaringType = targetMethod.GetDeclaringType();
            if (targetMethod.HasThis && (declaringType.IsValueType || declaringType is GenericParameter))
                IL.Emit(OpCodes.Box, declaringType);

            // Save the target
            IL.Emit(OpCodes.Stloc, _target);
            IL.Emit(OpCodes.Ldloc, _target);

            // Push the current method
            IL.PushMethod(targetMethod, module);

            // Push the stack trace
            PushStackTrace(IL, module);

            var systemType = module.Import(typeof(Type));

            // Save the parameter types
            var parameterCount = targetMethod.Parameters.Count;
            IL.Emit(OpCodes.Ldc_I4, parameterCount);
            IL.Emit(OpCodes.Newarr, systemType);
            IL.Emit(OpCodes.Stloc, _parameterTypes);

            IL.SaveParameterTypes(targetMethod, module, _parameterTypes);
            IL.Emit(OpCodes.Ldloc, _parameterTypes);

            // Save the type arguments
            var genericParameterCount = targetMethod.GenericParameters.Count;
            IL.Emit(OpCodes.Ldc_I4, genericParameterCount);
            IL.Emit(OpCodes.Newarr, systemType);
            IL.Emit(OpCodes.Stloc, _typeArguments);
            IL.PushGenericArguments(targetMethod, module, _typeArguments);
            IL.Emit(OpCodes.Ldloc, _typeArguments);

            // Push the return type
            IL.PushType(returnType, module);

            // Save the method arguments
            IL.Emit(OpCodes.Ldloc, _currentArguments);
            IL.Emit(OpCodes.Callvirt, _toArray);

            IL.Emit(OpCodes.Newobj, _invocationInfoCtor);
            IL.Emit(OpCodes.Stloc, _invocationInfo);
        }
開發者ID:zxl359592450,項目名稱:linfu,代碼行數:67,代碼來源:InterceptMethodCalls.cs


注:本文中的Mono.Cecil.Cil.CilWorker.PushGenericArguments方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。