Exemplo n.º 1
0
        public string AttributeDataType(bool isCollection, int rank, string type, bool isGeneric)
        {
            if (isCollection)
            {
                if (SelectData.ContainsKey(type))
                {
                    var unionType = string.Join('|', ExpandPossibleTypes(type));
                    return($"{string.Join("", Enumerable.Repeat("Array<", rank))}{unionType}{string.Join("", Enumerable.Repeat(">", rank))}");
                }
                else
                {
                    return($"{string.Join("", Enumerable.Repeat("Array<", rank))}{type}{string.Join("", Enumerable.Repeat(">", rank))}");
                }
            }

            // Item is used in functions.
            if (isGeneric)
            {
                return("T");
            }

            // https://github.com/ikeough/IFC-gen/issues/25
            if (type == "IfcSiUnitName")
            {
                return("IfcSIUnitName");
            }

            if (SelectData.ContainsKey(type))
            {
                return(string.Join('|', ExpandPossibleTypes(type)));
            }

            return(type);
        }
Exemplo n.º 2
0
        public string EntityConstructorParams(Entity data, bool includeOptional)
        {
            // Constructor parameters include the union of this type's attributes and all super type attributes.
            // A constructor parameter is created for every attribute which does not derive
            // from IFCRelationship.

            var parents = data.ParentsAndSelf().Reverse();
            var attrs   = parents.SelectMany(p => p.Attributes);

            if (!attrs.Any())
            {
                return(string.Empty);
            }

            var validAttrs = includeOptional ? AttributesWithOptional(attrs) : AttributesWithoutOptional(attrs);

            return(string.Join(", ", validAttrs.Select(a => $"{a.ParameterName} : {(SelectData.ContainsKey(a.Type)?string.Join('|',SelectData[a.Type].Values):a.Type)}")));
        }
Exemplo n.º 3
0
        private IEnumerable <string> ExpandPossibleTypes(string baseType)
        {
            if (!SelectData.ContainsKey(baseType))
            {
                // return right away, it's not a select
                return(new List <string> {
                    baseType
                });
            }

            var values = SelectData[baseType].Values;
            var result = new List <string>();

            foreach (var v in values)
            {
                result.AddRange(ExpandPossibleTypes(v));
            }

            return(result);
        }