Exemple #1
0
        private void AddActivateMixinDependenciesMethod(CodeGeneratorProxy mixinsClassCodeGenerator, TargetLevelCodeGeneratorPipelineState manager)
        {
            const string targetInstanceMethodParameterName = "target";

            var methodBodyStatements = new StringBuilder();

            foreach (var mixin in manager.CodeGenerationPlan.MixinGenerationPlans.Values)
            {
                methodBodyStatements.AppendFormat(
                    "{0}.{1}({2};",
                    mixin.MasterWrapperPlan.MasterWrapperInstanceNameInMixinsContainer,
                    manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsActivateMixinDependenciesMethodName,
                    targetInstanceMethodParameterName);
            }


            mixinsClassCodeGenerator.CreateMethod(
                modifier:
                "public",
                returnTypeFullName:
                "void",
                methodName:
                manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsActivateMixinDependenciesMethodName,
                parameters:
                new[]
            {
                new KeyValuePair <string, string>(
                    manager.TargetSourceTypeDeclaration.GetFullTypeName(),
                    targetInstanceMethodParameterName)
            },
                methodBody:
                methodBodyStatements.ToString());
        }
Exemple #2
0
        private void ProcessAbstractMembers(
            pMixinGeneratorPipelineState manager, CodeGeneratorProxy requirementInterface)
        {
            foreach (var abstractMember in manager.CurrentMixinMembers
                     .GetUnimplementedAbstractMembers())
            {
                #region Process Methods
                if (abstractMember is IMethod)
                {
                    requirementInterface.CreateMethod(
                        string.Empty, //no modifier for interface member
                        abstractMember.ReturnType.GetOriginalFullNameWithGlobal(),
                        GetAbstractMemberImplementationName(abstractMember),
                        (abstractMember as IMethod).Parameters.ToKeyValuePair(),
                        string.Empty,
                        (abstractMember as IMethod).GetGenericMethodConstraints(
                            manager.BaseState.Context.TypeResolver.Compilation));
                }
                #endregion

                #region Process Properties
                else if (abstractMember is IProperty)
                {
                    requirementInterface.CreateProperty(
                        string.Empty, //no modifier for interface member
                        abstractMember.ReturnType.GetOriginalFullNameWithGlobal(),
                        GetAbstractMemberImplementationName(abstractMember),
                        (abstractMember as IProperty).CanGet ? "get;" : "",
                        (abstractMember as IProperty).CanSet ? "set;" : "");
                }
                #endregion
            }
        }
Exemple #3
0
        private void ProcessConstructors(pMixinGeneratorPipelineState manager, CodeGeneratorProxy requirementInterface)
        {
            bool hasANonParamaterlessConstructor =
                manager.CurrentpMixinAttribute.Mixin.GetConstructors()
                .Any(c => !c.Parameters.Any());

            if (hasANonParamaterlessConstructor &&
                !manager.CurrentpMixinAttribute.Mixin.GetDefinition().IsAbstract&&
                !manager.CurrentpMixinAttribute.ExplicitlyInitializeMixin)
            {
                return;
            }


            //Update ExplicitlyInitializeMixin - Changed mind, user has to always set
            //ExplicitlyInitializeMixin to true even if mixin does not have parameterless constructor.
            //They could be using a custom MixinActivator that uses DI
            //manager.CurrentpMixinAttribute.ExplicitlyInitializeMixin = true;
            if (!manager.CurrentpMixinAttribute.ExplicitlyInitializeMixin)
            {
                return;
            }


            var requiredMixinWrapperType =
                (manager.CurrentpMixinAttribute.Mixin.GetDefinition().IsAbstract)
                    ? GenerateMixinSpecificAutoGeneratedClass.GetFullNameForChildType(
                    manager,
                    GenerateAbstractMixinMembersWrapperClass.GetWrapperClassName(manager))
                    : manager.CurrentpMixinAttribute.Mixin.GetOriginalFullNameWithGlobal();

            //generate the mixin initialization method
            requirementInterface.CreateMethod(
                string.Empty, //no modifier for interface member
                requiredMixinWrapperType,
                GetInitializationMethod(manager),
                new List <KeyValuePair <string, string> >(),
                "");
        }
        private void CreateActivateDependencyMethod(CodeGeneratorProxy codeGenerator, MixinGenerationPlan mixinPlan)
        {
            const string targetInstanceMethodParameterName = "target";

            var methodBodyStatements = new StringBuilder();

            foreach (var dependency in mixinPlan.MasterWrapperPlan.MixinDependencies)
            {
                methodBodyStatements.AppendFormat(
                    @"  (({0}){1}).Dependency = {2};
                        (({0}){1}).OnDependencySet();",

                    dependency.GetOriginalFullNameWithGlobal(),
                    MasterWrapperPlan.MixinInstanceDataMemberName,
                    targetInstanceMethodParameterName);
            }

            codeGenerator.CreateMethod(
                modifier:
                "public",
                returnTypeFullName:
                "void",
                methodName:
                mixinPlan.CodeGenerationPlan.TargetCodeBehindPlan.MixinsActivateMixinDependenciesMethodName,
                parameters:
                new[]
            {
                new KeyValuePair <string, string>(
                    mixinPlan.CodeGenerationPlan.SourceClass.GetFullTypeName(),
                    targetInstanceMethodParameterName)
            },
                methodBody:
                methodBodyStatements.ToString()
                //make sure method has at least an empty body
                .IfEmpty("{}"));
        }
        public bool PerformTask(TargetLevelCodeGeneratorPipelineState manager)
        {
            var codeGenerator =
                new CodeGeneratorProxy(manager.TargetCodeBehindTypeDeclaration);

            const string targetInstanceMethodParameterName = "target";

            foreach (var conversionPlan in manager.CodeGenerationPlan.TargetCodeBehindPlan.ImplicitCoversionPlans)
            {
                codeGenerator.CreateMethod(
                    modifier:
                    "public static implicit",
                    returnTypeFullName:
                    "operator",
                    methodName:
                    conversionPlan.ConversionTargetType.GetOriginalFullNameWithGlobal(),
                    parameters:
                    new []
                {
                    new KeyValuePair <string, string>(
                        manager.TargetCodeBehindTypeDeclaration.Name,
                        targetInstanceMethodParameterName)
                },
                    methodBody:
                    string.Format(
                        "return {0}.{1}.{2};",
                        targetInstanceMethodParameterName,
                        conversionPlan.MixinGenerationPlan.MasterWrapperPlan
                        .MasterWrapperInstanceNameAvailableFromTargetCodeBehind,
                        MasterWrapperPlan.MixinInstanceDataMemberName)
                    );
            }


            return(true);
        }