Esempio n. 1
0
        public bool PerformTask(TargetLevelCodeGeneratorPipelineState manager)
        {
            var codeGenerator =
                new CodeGeneratorProxy(manager.TargetCodeBehindTypeDeclaration);

            var backingFiledName = "__" + manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsPropertyName;

            //create backing field
            codeGenerator.CreateDataMember(
                modifiers:
                "private",
                dataMemberTypeFullName:
                manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsClassName,
                dataMemberName:
                backingFiledName
                );

            //create private property
            codeGenerator.CreateProperty(
                modifier:
                "private",
                returnTypeFullName:
                manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsClassName,
                propertyName:
                manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsPropertyName,
                getterMethodBody:
                string.Format(
                    @"
                                get 
                                {{
                                    if (null == {0})
                                    {{
                                        lock({1}.{2})
                                        {{
                                                if (null == {0})
                                                {{
                                                    {0} = new {1}(this);
                                                    {0}.{3}(this);
                                                }}
                                        }}
                                    }}
    
                                    return {0};
                                }}
                            ",
                    backingFiledName,
                    manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsClassName,
                    manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsLockVariableName,
                    manager.CodeGenerationPlan.TargetCodeBehindPlan.MixinsActivateMixinDependenciesMethodName)
                ,
                setterMethodBody:
                string.Empty     //no setter
                );

            return(true);
        }
 private void GenerateMixinInstanceDataMember(CodeGeneratorProxy codeGenerator, MixinLevelCodeGeneratorPipelineState manager)
 {
     codeGenerator.CreateDataMember(
         modifiers:
         //must be public for implicit conversion operator
         "public",
         dataMemberTypeFullName:
         manager.MixinGenerationPlan.MasterWrapperPlan.MixinInstanceTypeFullName,
         dataMemberName:
         MasterWrapperPlan.MixinInstanceDataMemberName);
 }
Esempio n. 3
0
 private void AddLockDataMember(CodeGeneratorProxy mixinsClassCodeGenerator, CodeGenerationPlan codeGenerationPlan)
 {
     mixinsClassCodeGenerator.CreateDataMember(
         modifiers:
         "public static",
         dataMemberTypeFullName:
         "global::System.Object",
         dataMemberName:
         codeGenerationPlan.TargetCodeBehindPlan.MixinsLockVariableName,
         initializerExpression:
         "= new global::System.Object();");
 }
Esempio n. 4
0
 private void AddMixinDataMembers(CodeGeneratorProxy mixinsClassCodeGenerator, TargetLevelCodeGeneratorPipelineState manager)
 {
     foreach (var mixin in manager.CodeGenerationPlan.MixinGenerationPlans.Values)
     {
         mixinsClassCodeGenerator.CreateDataMember(
             modifiers:
             "public",
             dataMemberTypeFullName:
             GetMasterWrapperFullTypeName(mixin),
             dataMemberName:
             mixin.MasterWrapperPlan.MasterWrapperInstanceNameInMixinsContainer);
     }
 }