protected string GetAttributeState(Attribute attribute)
        {
            const string enu  = "EntityAttributeState.";
            var          expl = attribute as ExplicitAttribute;

            if (expl != null && expl.OptionalFlag)
            {
                return(enu + "Optional");
            }
            if (expl != null)
            {
                return(enu + "Mandatory");
            }

            if (attribute is InverseAttribute inverse)
            {
                return(enu + "Mandatory");
            }

            if (attribute is DerivedAttribute derived)
            {
                return(derived.Redeclaring != null ? enu + "DerivedOverride" : enu + "Derived");
            }

            throw new NotSupportedException("Unexpected type or configuration of attribute " + attribute.Name);
        }
 protected int GetAttributeGlobalOrder(Attribute attribute)
 {
     if (attribute is DerivedAttribute)
     {
         return(0);
     }
     return(AllAttributes.IndexOf(attribute) + 1);
 }
 protected int GetAttributeOrder(Attribute attribute)
 {
     if (attribute is ExplicitOrDerived expl)
     {
         return(GetAttributeIndex(expl) + 1);
     }
     return(-1);
 }
        protected string GetAttributeType(Attribute attribute)
        {
            if (attribute is InverseAttribute)
            {
                return("EntityAttributeType.Set");
            }

            var domain = GetDomain(attribute);

            if (domain == null)
            {
                throw new NotSupportedException("Unexpected type or configuration of attribute " + attribute.Name);
            }

            return(GetAttributeType(domain));
        }
        protected string GetAttributeMemberType(Attribute attribute)
        {
            var domain = GetDomain(attribute);

            if (domain == null)
            {
                throw new NotSupportedException("Unexpected type or configuration of attribute " + attribute.Name);
            }

            if (attribute is InverseAttribute inv)
            {
                return(GetAttributeType(inv.Domain));
            }

            return(!(domain is AggregationType aggr) ?
                   "EntityAttributeType.None" :
                   GetAttributeType(aggr.ElementType));
        }
        protected static BaseType GetDomain(Attribute attribute)
        {
            BaseType domain = null;

            if (attribute is ExplicitAttribute expl)
            {
                domain = expl.Domain;
            }
            if (attribute is InverseAttribute inverse)
            {
                domain = inverse.Domain;
            }
            if (attribute is DerivedAttribute derived)
            {
                domain = derived.Domain;
            }

            return(domain);
        }
        protected string GetAttributeMaxCardinality(Attribute attribute)
        {
            var domain = GetDomain(attribute);

            if (domain == null)
            {
                throw new NotSupportedException("Unexpected type or configuration of attribute " + attribute.Name);
            }

            if (attribute is InverseAttribute inverse)
            {
                domain = inverse.AggregationType;
            }

            //collect all levels of the aggregation
            if (!(domain is AggregationType enumType))
            {
                return("null");
            }
            var cardinality = new List <int>();

            while (enumType is AggregationType)
            {
                if (enumType is VariableSizeAggregationType aggr)
                {
                    cardinality.Add(aggr.UpperBound ?? -1);
                }
                else if (enumType is ArrayType arr)
                {
                    cardinality.Add(arr.UpperIndex);
                }
                else
                {
                    cardinality.Add(-1);
                }

                enumType = enumType.ElementType as AggregationType;
            }

            return($"new int [] {{ {string.Join(", ", cardinality)} }}");
        }
        protected string GetPrivateFieldName(Attribute attribute)
        {
            string name = attribute.Name;

            return("_" + name.First().ToString().ToLower() + name.Substring(1));
        }