Example #1
0
        public virtual IEnumerable <CodeAttributeDeclaration> NewCodeAttributeDeclsExplicit(CRflProperty aProperty)
        {
            var aAttributeName  = this.Tok.Trg_P_AutoCreate_Nme;
            var aAttributeValue = aProperty.GetAttributeValue(aAttributeName);

            if (aAttributeValue != string.Empty)
            {
                yield return(new CodeAttributeDeclaration(new CodeTypeReference(typeof(CbOrm.App.Sys.CAutoCreateAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(aProperty.GetAttribute(aAttributeName).Interpret(() => bool.Parse(aAttributeValue))))));
            }
        }
Example #2
0
        private void AddMembers(CRflTyp aPTyp, CodeTypeDeclaration aCdTypDcl, CRflProperty aProperty)
        {
            var    aModel            = aProperty.Model;
            var    aModelInterpreter = this.ModelInterpreter;
            var    aCodeDomBuilder   = this.CodeDomBuilder;
            var    aPTypNme          = this.ModelInterpreter.GetTypName(aPTyp, true);
            var    aCdPTypRef        = new CodeTypeReference(aPTypNme);
            var    aCdPTypRefExp     = new CodeTypeReferenceExpression(aCdPTypRef);
            var    aCTyp             = this.ModelInterpreter.GetReturnTyp(aProperty);
            var    aPrpNme           = aProperty.Name;
            string aMtaFldTypNme;
            var    aMtaPrpNme    = this.Tok.GetRelationyMetaInfoPropertyName(aPrpNme);
            var    aMtaPrpRefExp = new CodePropertyReferenceExpression(aCdPTypRefExp, aMtaPrpNme);
            var    aCTypRef      = this.CodeDomBuilder.NewCodeTypeRef(aCTyp);

            // Relations-Objects
            var aCrd           = this.ModelInterpreter.GetCardinality(aProperty);
            var aRelTypName    = this.ModelInterpreter.GetClassName(aCrd);
            var aRelSystemType = CRef.GetRefClass(aCrd);
            var aCdRTypRef     = new CodeTypeReference(aRelTypName, this.CodeDomBuilder.NewCodeTypeRef(aPTyp), aCTypRef);
            var aCtorArgs1     = new CodeExpression[] { new CodeThisReferenceExpression(), aMtaPrpRefExp };
            var aCtorArgsBuildAttribIsDefined = aRelSystemType.IsNullRef() ? false : aRelSystemType.IsDefined(typeof(CGenCtorArgsBuilderAttribute), true);
            var aWriteOnlyBySystem            = aProperty.Interpret(() => bool.Parse(aProperty.GetAttributeValue(this.Tok.Trg_P_A_WriteOnlyBySystem, false.ToString)));
            var aCtorArgs2            = aWriteOnlyBySystem ? new CodeExpression[] { new CodeObjectCreateExpression(typeof(CAccessKey)) } : new CodeExpression[] { };
            var aCtorArgBuilderAttrib = aCtorArgsBuildAttribIsDefined ? aRelSystemType.GetCustomAttribute <CGenCtorArgsBuilderAttribute>(true) : default(CGenCtorArgsBuilderAttribute);
            var aCtorArgs3            = aCtorArgBuilderAttrib.IsNullRef() ? new CodeExpression[] { } : aCtorArgBuilderAttrib.NewCtorArgs(aModelInterpreter, aCodeDomBuilder, aProperty);
            var aCtorArgs             = aCtorArgs1.Concat(aCtorArgs2).Concat(aCtorArgs3);
            var aNewExp  = new CodeObjectCreateExpression(aCdRTypRef, aCtorArgs.ToArray());
            var aIsClass = true;
            var aLazyPrp = this.CodeDomBuilder.NewLazyLoadPrperty(aCdRTypRef, aIsClass, this.ModelInterpreter.GetEntityRefPropertyName(aProperty), aNewExp, MemberAttributes.Public | MemberAttributes.Final);

            aCdTypDcl.Members.Add(aLazyPrp.Item1);
            aCdTypDcl.Members.Add(aLazyPrp.Item2);
            var aCdPrp = aLazyPrp.Item1;

            aMtaFldTypNme = this.Tok.GeRelationMetaInfoTypName(aRelTypName);

            // Property.Attributes from System
            aCdPrp.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(CTargetTypeAttribute)), new CodeAttributeArgument(new CodeTypeOfExpression(aCTypRef))));


            // Property.Attributes from Model
            var aCdAs = this.CodeDomBuilder.NewCodeAttributeDecls(aProperty, this.ModelInterpreter);

            aCdPrp.CustomAttributes.AddRange(aCdAs.ToArray());



            // Property.NetaInfo.Field
            var aMtaFldNme = this.Tok.GetRelationMetaInfoFieldName(aPrpNme);
            //aMtaFldTypNme = this.Tok.Trg_C_Mta_P_Fld_Nme;
            var aCdMtaFldTypRef  = new CodeTypeReference(aMtaFldTypNme);
            var aCdMtaPrpFldDcl  = new CodeMemberField(aMtaFldTypNme, aMtaFldNme);
            var aCdMtaPrpInitExp = new CodeObjectCreateExpression(aCdMtaFldTypRef,
                                                                  this.CodeDomBuilder.NewTypeOfExpression(aPTypNme),
                                                                  this.CodeDomBuilder.NewNameOfPrpertyExpression(aPrpNme)
                                                                  );

            aCdMtaPrpFldDcl.Type       = aCdMtaFldTypRef;
            aCdMtaPrpFldDcl.Attributes = MemberAttributes.Static
                                         | MemberAttributes.Private
            ;
            aCdMtaPrpFldDcl.InitExpression = aCdMtaPrpInitExp;
            aCdTypDcl.Members.Add(aCdMtaPrpFldDcl);

            var aCdMtaFldRefExp = new CodeFieldReferenceExpression(aCdPTypRefExp, aMtaFldNme);

            // Property.MetaInfo.Property
            var aCdMtaPrp = new CodeMemberProperty();

            aCdMtaPrp.Name       = aMtaPrpNme;
            aCdMtaPrp.Type       = aCdMtaFldTypRef;
            aCdMtaPrp.Attributes = MemberAttributes.Static
                                   | MemberAttributes.Public
            ;
            aCdMtaPrp.HasGet = true;
            aCdMtaPrp.GetStatements.Add(new CodeMethodReturnStatement(aCdMtaFldRefExp));
            aCdTypDcl.Members.Add(aCdMtaPrp);
        }
Example #3
0
 public virtual string GetInit(CRflProperty aPrp) => aPrp.GetAttributeValue(this.Tok.Mdl_P_A_Nme_Init).DefaultIfEmpty(() => this.GetInit(this.GetReturnTyp(aPrp)));
Example #4
0
 public virtual CCardinalityEnum GetCardinality(CRflProperty aPrp) => aPrp.GetAttributeValue(this.Tok.Mdl_P_A_Nme_Crd).DefaultIfEmpty(aCardinalityText => ("R" + aCardinalityText.Replace(":", string.Empty)).ParseEnum <CCardinalityEnum>(), () => this.GetIsObject(this.GetReturnTyp(aPrp)) ? CCardinalityEnum.R1NC : CCardinalityEnum.Skalar);
Example #5
0
 public virtual string GetReturnTypName(CRflProperty aPrp) => this.GetIsEnum(aPrp.DeclaringTyp)
                                                            ? aPrp.DeclaringTyp.Name
                                                            : aPrp.Name.Length == 0 ? string.Empty : aPrp.GetAttributeValue(this.Tok.Mdl_P_A_Typ_Nme).DefaultIfEmpty(() => aPrp.Name);