Esempio n. 1
0
        /// <summary>
        /// Returns list of enums defined in the service model.
        /// </summary>
        /// <param name="includeParentEnums">Includes enums from current service model, which are also
        /// defined in the parent model.</param>
        /// <returns></returns>
        public IEnumerable <Enumeration> Enumerations(bool includeParentEnums)
        {
            var list = new List <Enumeration>();

            foreach (KeyValuePair <string, JsonData> kvp in DocumentRoot[ShapesKey])
            {
                var type = kvp.Value["type"];
                if (type != null && type.ToString() == "string" && kvp.Value["enum"] != null)
                {
                    list.Add(new Enumeration(this, kvp.Key, kvp.Value));
                }
            }
            list = list.OrderBy(x => x.Name).ToList();

            if (includeParentEnums || this.ParentModel == null)
            {
                return(list);
            }
            else
            {
                // Remove enums already defined in the parent model
                return(list.Where(e => ParentModel.Enumerations(true).All(en => !e.ModelName.Equals(en.ModelName))));
            }
        }