예제 #1
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
            }
        }
        private void ImplementIContainsMixin(
            CodeGeneratorProxy codeBehind,
            MixinGenerationPlan mgp)
        {
            var containMixinInterfaceName =
                string.Format(
                    "global::{0}.{1}<{2}>",
                    typeof(IContainMixin <>).Namespace,
                    "IContainMixin",
                    mgp.MixinAttribute.Mixin.GetOriginalFullNameWithGlobal());

            codeBehind.ImplementInterface(
                containMixinInterfaceName);

            codeBehind.CreateProperty(
                modifier:
                //implement explicitly
                string.Empty,
                returnTypeFullName:
                mgp.MixinAttribute.Mixin.GetOriginalFullNameWithGlobal(),
                propertyName:
                containMixinInterfaceName + ".MixinInstance",
                getterMethodBody:
                string.Format(
                    "get{{ return {0}.{1}; }}",
                    mgp.MasterWrapperPlan.MasterWrapperInstanceNameAvailableFromTargetCodeBehind,
                    MasterWrapperPlan.MixinInstanceDataMemberName),
                setterMethodBody:
                //no setter
                string.Empty
                );
        }
예제 #3
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 GenerateVirtualFuncDataMembers(CodeGeneratorProxy codeGenerator, MixinLevelCodeGeneratorPipelineState manager)
        {
            foreach (var mw in manager.MixinGenerationPlan.MasterWrapperPlan.VirtualMembers)
            {
                if (mw.Member is IMethod)
                {
                    var virtualFuncReturnType =
                        (mw.Member as IMethod).ReturnType.Kind == TypeKind.Void
                            ? typeof(Action).GetOriginalFullNameWithGlobal()
                            : string.Format("global::System.Func<{0}>",
                                            string.Join(",",
                                                        (mw.Member as IMethod).Parameters
                                                        .Select(x => x.Type.GetOriginalFullNameWithGlobal())
                                                        .Concat(new[] { mw.Member.ReturnType.GetOriginalFullNameWithGlobal() })));

                    codeGenerator.CreateProperty(
                        modifier:
                        "public",
                        returnTypeFullName:
                        virtualFuncReturnType,
                        propertyName:
                        mw.ImplementationDetails.VirtualMemberFunctionName,
                        getterMethodBody:
                        "get;",
                        setterMethodBody:
                        "set;");
                }
                else if (mw.Member is IProperty)
                {
                    //Get
                    if ((mw.Member as IProperty).CanGet && !(mw.Member as IProperty).Getter.IsPrivate)
                    {
                        codeGenerator.CreateProperty(
                            modifier:
                            "public",
                            returnTypeFullName:
                            "global::System.Func<" + mw.Member.ReturnType.GetOriginalFullNameWithGlobal() + ">",
                            propertyName:
                            mw.ImplementationDetails.VirtualMemberFunctionName + "Get",
                            getterMethodBody:
                            "get;",
                            setterMethodBody:
                            "set;");
                    }
                    //Set
                    if ((mw.Member as IProperty).CanSet && !(mw.Member as IProperty).Setter.IsPrivate)
                    {
                        codeGenerator.CreateProperty(
                            modifier:
                            "public",
                            returnTypeFullName:
                            "global::System.Action<" + mw.Member.ReturnType.GetOriginalFullNameWithGlobal() + ">",
                            propertyName:
                            mw.ImplementationDetails.VirtualMemberFunctionName + "Set",
                            getterMethodBody:
                            "get;",
                            setterMethodBody:
                            "set;");
                    }
                }
            }
        }