Exemplo n.º 1
0
        protected virtual void EmitThrowIfExceptionListHasAny(CompositeMethodGenerationInfo methodGenInfo, CILConstructor exceptionCtor)
        {
            var exceptionListB = methodGenInfo.GetLocalOrThrow(LB_EXCEPTION_LIST);
            var il             = methodGenInfo.IL;
            var noThrowLabel   = il.DefineLabel();

            il
            .EmitLoadLocal(exceptionListB)
            .EmitBranch(BranchType.IF_FALSE, noThrowLabel)
            .EmitLoadLocal(exceptionListB)
            .EmitThrowNewException(exceptionCtor)
            .MarkLabel(noThrowLabel);
        }
        protected override void EmitAfterCompositeMethodBodyBegan(
            IEnumerable <FragmentTypeGenerationInfo> fragmentTypeGenerationInfos,
            CompositeTypeGenerationInfo thisGenerationInfo,
            CompositeMethodGenerationInfo thisMethodGenerationInfo,
            SPI.Model.CompositeMethodModel compositeMethodModel
            )
        {
            var instanceableModel = compositeMethodModel.CompositeModel;

            // Need to emit code related to activation
            var il         = thisMethodGenerationInfo.IL;
            var cInstanceB = thisMethodGenerationInfo.GetLocalOrThrow(LB_C_INSTANCE);

            LocalBuilder compositeMethodModelB     = null;
            Boolean      hasOnInvocationInjections = this.HasOnInvocationInjections(compositeMethodModel.CompositeModel.SpecialMethods.Where(sMethod => sMethod.AllAttributes.OfType <ActivateAttribute>().Any() || sMethod.AllAttributes.OfType <PrototypeAttribute>().Any()));

            if (hasOnInvocationInjections)
            {
                this.InitializeComplexMethodModelLocalIfNecessary(compositeMethodModel, thisMethodGenerationInfo, out compositeMethodModelB);
            }

            // cInstance.ActivateIfNeeded(<method-index>, <gargs-info>, <next fragment>);
            il.EmitLoadLocal(cInstanceB)
            .EmitLoadInt32(compositeMethodModel.MethodIndex);
            if (thisMethodGenerationInfo.Builder.GenericArguments.Count > 0)
            {
                // new MethodGenericArgumentsInfo(<method-handle>, <type-handle>)
                var cMethodInfo = thisMethodGenerationInfo.OverriddenMethod.MakeGenericMethod(thisMethodGenerationInfo.GenericArguments.ToArray());
                il.Add(new OpCodeInfoWithMethodToken(
                           OpCodes.Ldtoken,
                           cMethodInfo))
                .Add(new OpCodeInfoWithTypeToken(
                         OpCodes.Ldtoken,
                         cMethodInfo.DeclaringType
                         ));
                il.EmitNewObject(this.METHOD_GENERIC_ARGUMENTS_INFO_CTOR);
            }
            else
            {
                il.EmitLoadNull();
            }

            if (hasOnInvocationInjections)
            {
                il.EmitLoadLocal(compositeMethodModelB);
                if (compositeMethodModel.Concerns.Any())
                {
                    il.EmitCall(CONCERN_MODELS_GETTER)
                    .EmitLoadInt32(0)
                    .EmitCall(CONCERN_MODELS_INDEXER);
                }
                else
                {
                    il.EmitCall(MIXIN_MODEL_GETTER);
                }
            }
            else
            {
                il.EmitLoadNull();
            }
            il.EmitCall(SERVICE_COMPOSITE_ACTIVATE_IF_NEEDED_METHOD);
        }