Ejemplo n.º 1
0
        /*--------------------------------------------------------------------------------------------*/
        private static List <FabSpecObjectProp> BuildEnumProps(string pEnumName, EnumItem pItem)
        {
            var enumProps = new List <FabSpecObjectProp>();

            if (pItem == null)
            {
                pItem = new EnumItem();
            }

            PropertyInfo[] props = pItem.GetType().GetProperties(
                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            foreach (PropertyInfo pi in props)
            {
                var p = new FabSpecObjectProp();
                p.Name        = pi.Name;
                p.Description = ApiLang.Text <EnumPropText>(pEnumName + "_" + p.Name);
                p.Type        = ApiLang.TypeName(pi.PropertyType);
                enumProps.Add(p);
            }

            return(enumProps);
        }
Ejemplo n.º 2
0
        /*--------------------------------------------------------------------------------------------*/
        private static FabSpecObjectProp BuildObjectProp(
            string pObjName, PropertyInfo pProp, bool pSkipText)
        {
            DataMemberAttribute dataMem = GetAttribute <DataMemberAttribute>(pProp);

            var p = new FabSpecObjectProp();

            p.Name = (dataMem == null ? pProp.Name : dataMem.Name);
            p.Type = ApiLang.TypeName(pProp.PropertyType);

            if (!pSkipText)
            {
                string key = pObjName.Substring(3) + "_" + pProp.Name;

                if (pObjName.IndexOf("CreateFab") == 0)
                {
                    key = pObjName.Replace("CreateFab", "Create") + "_" + pProp.Name;
                }

                p.Description = ApiLang.Text <DtoPropText>(key);
            }

            ////

            SpecLenAttribute         specLen   = GetAttribute <SpecLenAttribute>(pProp);
            SpecRangeAttribute       specRange = GetAttribute <SpecRangeAttribute>(pProp);
            SpecRegexAttribute       specReg   = GetAttribute <SpecRegexAttribute>(pProp);
            SpecUniqueAttribute      specUni   = GetAttribute <SpecUniqueAttribute>(pProp);
            SpecToLowerCaseAttribute specLow   = GetAttribute <SpecToLowerCaseAttribute>(pProp);
            SpecFromEnumAttribute    specEnum  = GetAttribute <SpecFromEnumAttribute>(pProp);

            if (HasAttribute <SpecOptionalAttribute>(pProp))
            {
                p.IsOptional = true;
            }

            if (specLen != null)
            {
                p.LenMin = specLen.Min;
                p.LenMax = specLen.Max;
            }

            if (specRange != null)
            {
                p.Min = specRange.Min;
                p.Max = specRange.Max;
            }

            if (specReg != null)
            {
                p.ValidRegex = specReg.Pattern;
            }

            if (specUni != null)
            {
                p.IsUnique = true;
            }

            if (specLow != null)
            {
                p.ToLowerCase = true;
            }

            if (specEnum != null)
            {
                p.Enum = specEnum.Name;
            }

            return(p);
        }