当前位置: 首页>>代码示例>>C#>>正文


C# InstructionBlock.AddInstructionSequence方法代码示例

本文整理汇总了C#中InstructionBlock.AddInstructionSequence方法的典型用法代码示例。如果您正苦于以下问题:C# InstructionBlock.AddInstructionSequence方法的具体用法?C# InstructionBlock.AddInstructionSequence怎么用?C# InstructionBlock.AddInstructionSequence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InstructionBlock的用法示例。


在下文中一共展示了InstructionBlock.AddInstructionSequence方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence sequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(sequence, NodePosition.After, null);
            InstructionWriter writer = context.InstructionWriter;
            writer.AttachInstructionSequence(sequence);

            context.InstructionWriter.EmitInstructionLocalVariable(OpCodeNumber.Ldloc, context.ReturnValueVariable);
            context.InstructionWriter.EmitInstructionType(OpCodeNumber.Box,
                                                          context.ReturnValueVariable.LocalVariable.Type);
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Ldnull);
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Ceq);

            InstructionSequence nextSequence = context.Method.MethodBody.CreateInstructionSequence();

            context.InstructionWriter.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, nextSequence);
            context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, "return value is null");
            context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Newobj,
                                                            context.Method.Module.FindMethod(
                                                                typeof (ArgumentNullException).GetConstructor(new[]
                                                                                                                  {
                                                                                                                      typeof
                                                                                                                          (
                                                                                                                          string
                                                                                                                          )
                                                                                                                  }),
                                                                BindingOptions.Default));
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Throw);

            block.AddInstructionSequence(nextSequence, NodePosition.After, sequence);

            writer.DetachInstructionSequence();
        }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:33,代码来源:NonNullReturnAdvice.cs

示例2: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence nextSequence = null;
            InstructionSequence sequence = null;

            sequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(sequence, NodePosition.Before, null);
            context.InstructionWriter.AttachInstructionSequence(sequence);

            context.InstructionWriter.EmitInstructionParameter(OpCodeNumber.Ldarg, this.paramDef);
            context.InstructionWriter.EmitInstructionType(OpCodeNumber.Box, this.paramDef.ParameterType);
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Ldnull);
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Ceq);

            nextSequence = context.Method.MethodBody.CreateInstructionSequence();

            context.InstructionWriter.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, nextSequence);
            context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, this.paramDef.Name);
            context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Newobj,
                                                            context.Method.Module.FindMethod(
                                                                typeof (ArgumentNullException).GetConstructor(
                                                                    new[] {typeof (string)}),
                                                                BindingOptions.Default));
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Throw);

            context.InstructionWriter.DetachInstructionSequence();
            block.AddInstructionSequence(nextSequence, NodePosition.After, sequence);
            sequence = nextSequence;
            context.InstructionWriter.AttachInstructionSequence(sequence);

            context.InstructionWriter.DetachInstructionSequence();
        }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:32,代码来源:NonNullParameterAdvice.cs

示例3: Weave

        /// <summary>
        /// Weaves the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="block">The block.</param>
        public void Weave(WeavingContext context, InstructionBlock block)
        {
            LocalVariableSymbol parameters = block.DefineLocalVariable(context.Method.Module.FindType(typeof(ParameterDictionary), BindingOptions.Default), NameGenerator.Generate("parameters"));

            InstructionSequence entrySequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(entrySequence, NodePosition.Before, null);

            InstructionWriter writer = context.InstructionWriter;
            writer.AttachInstructionSequence(entrySequence);
            writer.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);

            writer.EmitInstructionMethod(OpCodeNumber.Call, context.Method.Module.FindMethod(typeof(InternalHelperMethods).GetMethod("CreateParameterCollection"), BindingOptions.Default));

            IMethod add = context.Method.Module.FindMethod(typeof(ParameterDictionary).GetMethod("Add", new[] { typeof(string), typeof(object) }), BindingOptions.Default);

            short parameterIndex = context.Method.IsStatic ? (short)0 : (short)1;
            foreach (var parameter in method.Parameters)
            {
                writer.EmitInstruction(OpCodeNumber.Dup);

                writer.EmitInstructionString(OpCodeNumber.Ldstr, new LiteralString(parameter.Name));
                writer.EmitInstructionInt16(OpCodeNumber.Ldarg, parameterIndex++);

                if (parameter.ParameterType.GetSystemType(null, null).IsValueType)
                {
                    writer.EmitInstructionType(OpCodeNumber.Box, parameter.ParameterType);
                }

                writer.EmitInstructionMethod(OpCodeNumber.Callvirt, add);
            }

            writer.EmitInstructionLocalVariable(OpCodeNumber.Stloc, parameters);

            writer.DetachInstructionSequence();
        }
开发者ID:zevinganez,项目名称:code-o-matic,代码行数:40,代码来源:BuildParameterCollectionAdvice.cs

示例4: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence nextSequence = null;
            InstructionSequence sequence = null;

            sequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(sequence, NodePosition.Before, null);
            context.InstructionWriter.AttachInstructionSequence(sequence);

            IMethod isNullOrEmpty = context.Method.Module.FindMethod(typeof (string).GetMethod("IsNullOrEmpty"),
                                                                     BindingOptions.Default);

            // Checks if not empty

            context.InstructionWriter.EmitInstructionParameter(OpCodeNumber.Ldarg, paramDef);
            context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Call, isNullOrEmpty);

            nextSequence = context.Method.MethodBody.CreateInstructionSequence();

            context.InstructionWriter.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, nextSequence);
            context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, "Parameter is null or empty.");
            context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, this.paramDef.Name);
            context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Newobj,
                                                            context.Method.Module.FindMethod(
                                                                typeof (ArgumentException).GetConstructor(new[]
                                                                                                              {
                                                                                                                  typeof
                                                                                                                      (
                                                                                                                      string
                                                                                                                      ),
                                                                                                                  typeof
                                                                                                                      (
                                                                                                                      string
                                                                                                                      )
                                                                                                              }),
                                                                BindingOptions.Default));
            context.InstructionWriter.EmitInstruction(OpCodeNumber.Throw);

            context.InstructionWriter.DetachInstructionSequence();
            block.AddInstructionSequence(nextSequence, NodePosition.After, sequence);
            sequence = nextSequence;
            context.InstructionWriter.AttachInstructionSequence(sequence);

            context.InstructionWriter.DetachInstructionSequence();
        }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:45,代码来源:NonEmptyParameterAdvice.cs

示例5: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            IList<ParameterDeclaration> args = new List<ParameterDeclaration>();
            foreach(ParameterDeclaration p in context.Method.Parameters)
            {
                foreach (CustomAttributeDeclaration c in p.CustomAttributes)
                {
                    object obj = c.ConstructRuntimeObject();
                    if (obj is NonNullAttribute)
                    {
                        args.Add(p);
                    }
                }
            }

            InstructionSequence nextSequence = null;
            InstructionSequence sequence = null;

            sequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(sequence, NodePosition.Before, null);
            context.InstructionWriter.AttachInstructionSequence(sequence);

            foreach (ParameterDeclaration p in args)
            {
                context.InstructionWriter.EmitInstructionParameter(OpCodeNumber.Ldarg, p);
                context.InstructionWriter.EmitInstructionType(OpCodeNumber.Box, p.ParameterType);
                context.InstructionWriter.EmitInstruction(OpCodeNumber.Ldnull);
                context.InstructionWriter.EmitInstruction(OpCodeNumber.Ceq);

                nextSequence = context.Method.MethodBody.CreateInstructionSequence();

                context.InstructionWriter.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, nextSequence);
                context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, (LiteralString)p.Name);
                context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Newobj, context.Method.Module.FindMethod(typeof(ArgumentNullException).GetConstructor(new Type[] { typeof(string) }), BindingOptions.Default));
                context.InstructionWriter.EmitInstruction(OpCodeNumber.Throw);

                context.InstructionWriter.DetachInstructionSequence();
                block.AddInstructionSequence(nextSequence, NodePosition.After, sequence);
                sequence = nextSequence;
                context.InstructionWriter.AttachInstructionSequence(sequence);
            }

            context.InstructionWriter.DetachInstructionSequence();
        }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:44,代码来源:NonNullParameterAdvice.cs

示例6: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence sequence = null;

            sequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(sequence, NodePosition.After, null);
            context.InstructionWriter.AttachInstructionSequence(sequence);

            context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Call, context.Method.Module.FindMethod(m_type.Methods.GetOneByName("get_Instance").GetReflectionWrapper(new Type[]{},new Type[]{}),BindingOptions.Default));
            context.InstructionWriter.DetachInstructionSequence();
        }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:11,代码来源:SingletonAdvice.cs

示例7: AddPropertyGuard

        public static void AddPropertyGuard(PropertyDeclaration property, MethodBodyTransformationContext context, InstructionBlock block, InstructionWriter writer)
        {
            var propertyType = property.PropertyType;
            var methodBody = block.MethodBody;

            var sequence = block.AddInstructionSequence(null, NodePosition.After, null);
            if (sequence == null) return;

            var oldValueVariable =
                block.DefineLocalVariable(propertyType, string.Format("old{0}Value", property.Name));
            var assets = GetTransformationAssets(property.Module);

            writer.AttachInstructionSequence(sequence);
            var isLocationBinding = CheckIfIsLocationBinding(methodBody,assets);
            if (isLocationBinding) {
                writer.AssignValue_LocalVariable(oldValueVariable
                    , () => writer.Call_MethodOnTarget(property.GetGetter()
                        ,
                        () => {
                            //Load the instance parameter of the SetValue method
                            //and convert it to the type
                            writer.EmitInstruction(OpCodeNumber.Ldarg_1);
                            //writer.EmitInstructionLoadIndirect(Assets.ObjectTypeSignature);
                            writer.EmitInstructionType(OpCodeNumber.Ldobj, assets.ObjectTypeSignature);
                            writer.EmitConvertFromObject(property.Parent);
                        }
                    )
                );
                //On the location binding the value parameter is at psotion 3
                writer.EmitInstruction(OpCodeNumber.Ldarg_3);
            } else {
                writer.AssignValue_LocalVariable(oldValueVariable,
                                                    () => writer.Get_PropertyValue(property));
                //For a normal property the value parameter is at position 1
                writer.EmitInstruction(OpCodeNumber.Ldarg_1);
            }
            if (propertyType.IsStruct()) {
                writer.EmitInstructionType(OpCodeNumber.Box, propertyType);
            }
            writer.Box_LocalVariableIfNeeded(oldValueVariable);
            var isPrimitive = propertyType.IsPrimitive();
            if (isPrimitive) {
                writer.Compare_Primitives();
            } else {
                //TODO: Try and use the equality operator when present
                writer.Compare_Objects(assets.ObjectEqualsMethod);
            }
            //writer.Leave_IfTrue(_context.LeaveBranchTarget);
            writer.Leave_IfTrue(context.LeaveBranchTarget);
            writer.DetachInstructionSequence();
        }
开发者ID:DamianReeves,项目名称:PostEdge,代码行数:51,代码来源:EnhancePropertySetterMethodBodyWrappingImplementation.cs

示例8: Weave

        public void Weave(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence entrySequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(entrySequence, NodePosition.Before, null);

            InstructionWriter writer = context.InstructionWriter;

            writer.AttachInstructionSequence(entrySequence);
            writer.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);

            Weave(context, writer);

            writer.DetachInstructionSequence();
        }
开发者ID:zevinganez,项目名称:code-o-matic,代码行数:14,代码来源:BaseLogAdvice.cs

示例9: ImplementOnException

                protected override void ImplementOnException(InstructionBlock block, ITypeSignature exceptionType, InstructionWriter writer)
                {
                    MethodDefDeclaration targetMethod = this.transformationInstance.AspectWeaverInstance.TargetElement as MethodDefDeclaration;
                    if (targetMethod == null)
                    {
                        return;
                    }

                    // TODO: nested types
                    string category = targetMethod.DeclaringType.Name;
                    ILoggingCategoryBuilder builder = this.backendInstance.GetCategoryBuilder(category);
                    InstructionSequence sequence = block.AddInstructionSequence(null, NodePosition.After, null);
                    writer.AttachInstructionSequence(sequence);

                    LocalVariableSymbol exceptionLocal = block.MethodBody.RootInstructionBlock.DefineLocalVariable(
                        exceptionType, DebuggerSpecialNames.GetVariableSpecialName("ex"));

                    LogSeverity logSeverity = LogSeverity.Warning;
                    if (builder.SupportsIsEnabled)
                    {
                        builder.EmitGetIsEnabled(writer, logSeverity);
                        InstructionSequence branchSequence = block.AddInstructionSequence(null, NodePosition.After, sequence);
                        writer.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, branchSequence);
                    }

                    builder.EmitWrite(writer, block, "An exception occurred:\n{0}", 1, logSeverity,
                                      w => w.EmitInstructionLocalVariable(OpCodeNumber.Stloc, exceptionLocal),
                                      (i, w) => w.EmitInstructionLocalVariable(OpCodeNumber.Ldloc, exceptionLocal));

                    writer.EmitInstruction(OpCodeNumber.Rethrow);
                    writer.DetachInstructionSequence();
                }
开发者ID:halad,项目名称:PostSharp-Toolkits,代码行数:32,代码来源:LoggingAspectTransformation.cs

示例10: EmitMessage

                private void EmitMessage(InstructionBlock block, InstructionWriter writer, MethodDefDeclaration targetMethod, string messageFormatString)
                {
                    // TODO: nested types
                    string category = targetMethod.DeclaringType.Name;
                    ILoggingCategoryBuilder builder = this.backendInstance.GetCategoryBuilder(category);

                    InstructionSequence sequence = block.AddInstructionSequence(null, NodePosition.After, null);
                    writer.AttachInstructionSequence(sequence);

                    if (builder.SupportsIsEnabled)
                    {
                        builder.EmitGetIsEnabled(writer, LogSeverity.Trace);
                        InstructionSequence branchSequence = block.AddInstructionSequence(null, NodePosition.After, sequence);
                        writer.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, branchSequence);
                    }

                    int parameterCount = Context.MethodMapping.MethodSignature.ParameterCount;
                    bool hasThis = Context.MethodMapping.MethodSignature.CallingConvention == CallingConvention.HasThis;

                    builder.EmitWrite(writer, block, messageFormatString, parameterCount, LogSeverity.Trace, null,
                                      (i, instructionWriter) =>
                                      {
                                          instructionWriter.EmitInstructionInt16(OpCodeNumber.Ldarg, (short)(hasThis ? i + 1 : i));
                                          instructionWriter.EmitConvertToObject(
                                              this.Context.MethodMapping.MethodSignature.GetParameterType(i));
                                      });

                    writer.DetachInstructionSequence();
                }
开发者ID:halad,项目名称:PostSharp-Toolkits,代码行数:29,代码来源:LoggingAspectTransformation.cs

示例11: WeaveExit

        private void WeaveExit(WeavingContext context, InstructionBlock block)
        {
            InstructionSequence exitSequence = context.Method.MethodBody.CreateInstructionSequence();
            block.AddInstructionSequence(exitSequence, NodePosition.Before, null);

            InstructionWriter iw = context.InstructionWriter;

            iw.AttachInstructionSequence(exitSequence);
            iw.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);

            MethodDefDeclaration onPropertyChangedMethod = FindOnPropertyChangedMethodFromContext(context);

            iw.EmitInstruction(OpCodeNumber.Ldarg_0);
            iw.EmitInstructionString(OpCodeNumber.Ldstr, _getMethod.Name.Substring(4));

            MethodBase systemMethod = onPropertyChangedMethod.GetSystemMethod(null, null, BindingOptions.Default);
            IMethod boundMethod = this._setMethod.Module.FindMethod(systemMethod, BindingOptions.Default);

            iw.EmitInstructionMethod(OpCodeNumber.Callvirt, boundMethod);

            iw.DetachInstructionSequence();
        }
开发者ID:luboshl,项目名称:propfu,代码行数:22,代码来源:NotifyPropertyChangedAdvice.cs

示例12: CallEventInvokerMethod

        private void CallEventInvokerMethod(IMethod method, InstructionBlock block, InstructionWriter writer)
        {
            if (method == null) return;
            if (block.MethodBody.ContainsCallToMethod(method)) return;

            var sequence = block.AddInstructionSequence(null, NodePosition.After, null);
            writer.AttachInstructionSequence(sequence);
            //writer.EmitInstructionString();
            writer.EmitInstruction(OpCodeNumber.Ldarg_0);
            writer.EmitInstructionString(OpCodeNumber.Ldstr, _transformationContext.Property.Name);
            //writer.EmitInstructionLocalVariable();
            if (method.IsVirtual) {
                writer.EmitInstructionMethod(OpCodeNumber.Callvirt, method);
            } else {
                writer.EmitInstructionMethod(OpCodeNumber.Call, method);
            }
            writer.DetachInstructionSequence();
        }
开发者ID:DamianReeves,项目名称:PostEdge,代码行数:18,代码来源:EnhancePropertySetterMethodBodyWrappingImplementation.cs

示例13: EmitMessage

                private void EmitMessage(InstructionBlock block, InstructionWriter writer, LogLevel logLevel, string messageFormatString, int[] arguments)
                {
                    MethodDefDeclaration targetMethod = Context.TargetElement as MethodDefDeclaration;
                    if (targetMethod == null)
                    {
                        return;
                    }

                    // TODO: nested types
                    string category = targetMethod.DeclaringType.Name;
                    ILoggingCategoryBuilder builder = this.backendInstance.GetCategoryBuilder(category);

                    InstructionSequence sequence = block.AddInstructionSequence(null, NodePosition.After, null);
                    writer.AttachInstructionSequence(sequence);

                    if (builder.SupportsIsEnabled)
                    {
                        builder.EmitGetIsEnabled(writer, logLevel);
                        InstructionSequence branchSequence = block.AddInstructionSequence(null, NodePosition.After, sequence);
                        writer.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, branchSequence);
                    }

                    bool useWrapper = ShouldUseWrapper(targetMethod);

                    builder.EmitWrite(writer, messageFormatString, arguments.Length, logLevel, null, (i, instructionWriter) =>
                    {
                        int index = arguments[i];
                        if (index == MessageArgumentsFormatter.ThisArgumentPosition)
                        {
                            this.methodMappingWriter.EmitLoadInstance(false, instructionWriter);
                        }
                        else if (index == MessageArgumentsFormatter.ReturnParameterPosition)
                        {
                            instructionWriter.EmitInstructionLocalVariable(OpCodeNumber.Ldloc, Context.ReturnValueVariable);
                            instructionWriter.EmitConvertToObject(Context.MethodMapping.MethodSignature.ReturnType);
                        }
                        else
                        {
                            this.methodMappingWriter.EmitLoadArgument(index, instructionWriter);

                            instructionWriter.EmitConvertToObject(this.methodMappingWriter.MethodMapping.MethodSignature.GetParameterType(index));
                        }
                    }, useWrapper);

                    writer.DetachInstructionSequence();
                }
开发者ID:olcayseker,项目名称:PostSharp-Toolkits,代码行数:46,代码来源:LoggingAspectTransformation.cs

示例14: Weave

            public void Weave(WeavingContext context, InstructionBlock block)
            {
                // Type whose constructor is being woven.
                TypeDefDeclaration wovenType = context.Method.DeclaringType;

                // Logging data for the woven type.
                PerTypeLoggingData perTypeLoggingData = this.parent.perTypeLoggingDatas[wovenType];

                InstructionSequence initializeSequence = context.Method.MethodBody.CreateInstructionSequence();

                block.AddInstructionSequence(initializeSequence, NodePosition.Before, null);

                context.InstructionWriter.AttachInstructionSequence(initializeSequence);
                context.InstructionWriter.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);

                // Get the declaring type of the constructor.
                context.WeavingHelper.GetRuntimeType(GenericHelper.GetTypeCanonicalGenericInstance(wovenType), context.InstructionWriter);
                // Stack: type.
                // Get the logger for the method_declaring_type.
                context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Call, this.parent.GetLoggerMethod);
                // Stack: logger.
                // Assign logger to the log variable.
                context.InstructionWriter.EmitInstructionField(OpCodeNumber.Stsfld, GenericHelper.GetFieldCanonicalGenericInstance(perTypeLoggingData.Log));
                // Stack: .

                context.InstructionWriter.DetachInstructionSequence();
            }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:27,代码来源:LogTask.cs

示例15: Weave

            public void Weave(WeavingContext context, InstructionBlock block)
            {
                // Type whose constructor is being woven.
                TypeDefDeclaration wovenType = context.Method.DeclaringType;

                // Logging data for the woven type.
                PerTypeLoggingData perTypeLoggingData = this.parent.perTypeLoggingDatas[wovenType];

                InstructionSequence initializeSequence = context.Method.MethodBody.CreateInstructionSequence();

                block.AddInstructionSequence(initializeSequence, NodePosition.Before, null);

                context.InstructionWriter.AttachInstructionSequence(initializeSequence);
                context.InstructionWriter.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);

                IAnnotationValue loggerPolicyAtt;
                sm_loggerPolicies.TryGetValue(wovenType.Name, out loggerPolicyAtt);

                //Use the helper to get the Logger's name.
                context.WeavingHelper.GetRuntimeType(GenericHelper.GetCanonicalGenericInstance(wovenType), context.InstructionWriter);
                // Stack: type.

                if (loggerPolicyAtt != null)
                {

                  //Two additional params are needed for this method.
                  LoggerPolicyAttribute att = (LoggerPolicyAttribute)(new CustomAttributeDeclaration(loggerPolicyAtt)).ConstructRuntimeObject();
                  context.InstructionWriter.EmitInstructionInt32(OpCodeNumber.Ldc_I4, (int)att.LoggerNamePolicy);
                  context.InstructionWriter.EmitInstructionInt32(OpCodeNumber.Ldc_I4, (int)att.GenericArgsLoggerNamePolicy);
                  context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Call, this.parent.registerLoggerWithPolicyMethod);
                  // Stack: string  (logger name)
                }
                else
                {
                  context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Call, this.parent.RegisterLoggerMethod);
                  // Stack: string  (logger name)
                }

                context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Call, this.parent.GetLoggerByStringMethod);
                // Stack: logger.

                // Assign logger to the log variable.
                context.InstructionWriter.EmitInstructionField(OpCodeNumber.Stsfld, GenericHelper.GetCanonicalGenericInstance(perTypeLoggingData.Log));
                // Stack: .

                context.InstructionWriter.DetachInstructionSequence();
            }
开发者ID:kamillangowski,项目名称:postsharp-user-plugins,代码行数:47,代码来源:LogTask.cs


注:本文中的InstructionBlock.AddInstructionSequence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。