public List <EngineEnum> GetEnums() { var results = new List <EngineEnum>(); if (Items != null) { var enumObj = Items["enum"] ?? null; if (enumObj != null) { var engineEnum = new EngineEnum() { Name = Name }; Type = Name; var childen = enumObj.Children(); foreach (var child in childen) { var name = child.ToObject <string>(); var shotEnumValues = Items["enumShort"] ?? null; var shotName = engineEnum.GetShotEnumName(name, shotEnumValues); engineEnum.Values.Add(new EngineEnumValue() { Name = name, ShotValue = shotName }); } results.Add(engineEnum); } } return(results); }
private List <EngineProperty> ReadProperties(JObject jObject, string tokenName, string className) { var results = new List <EngineProperty>(); try { var properties = GetValueFromProperty <JToken>(jObject, tokenName); if (properties == null) { return(results); } foreach (var property in properties) { var jprop = property as JProperty; logger.Debug($"Property name: {jprop.Name}"); var engineProperty = new EngineProperty(); dynamic propObject = null; if (property.First.Type == JTokenType.Object) { propObject = property.First as JObject; engineProperty = propObject.ToObject <EngineProperty>(); engineProperty.EnumShot = (propObject as JObject)["enumShort"] as JToken ?? null; } engineProperty.Name = jprop.Name; if (engineProperty.Description != null && engineProperty.Description.Contains("The default value is")) { if (!String.IsNullOrEmpty(engineProperty.Default)) { engineProperty.DefaultValueFromDescription = engineProperty.Default; } else { logger.Warn($"The default value was not found for the property: \"{engineProperty.Name}\" class: \"{className}\""); } } var refValue = GetValueFromProperty <string>(propObject, "$ref"); if (!String.IsNullOrEmpty(refValue)) { engineProperty.Ref = refValue; } if (jprop.Name == "$ref") { var refLink = jprop?.Value?.ToObject <string>() ?? null; logger.Debug($"Items Ref: {refLink}"); engineProperty.Ref = refLink; } if (engineProperty.Type == "array") { refValue = GetValueFromProperty <string>(propObject.items, "$ref"); if (String.IsNullOrEmpty(refValue)) { refValue = propObject.items.type.ToObject <string>(); } engineProperty.Ref = refValue; } if (engineProperty.Enum != null) { engineProperty.Type = GenerateEnumType(engineProperty.Name); engineProperty.IsEnumType = true; var engineEnum = new EngineEnum() { Name = engineProperty.Name, }; foreach (var enumValue in engineProperty.Enum) { var shotName = engineEnum.GetShotEnumName(enumValue, engineProperty.EnumShot); engineEnum.Values.Add(new EngineEnumValue() { Name = enumValue, ShotValue = shotName }); } var enumResult = EnumExists(engineEnum); if (enumResult == null) { EngineObjects.Add(engineEnum); engineEnum.Name = engineProperty.Type; } else { engineProperty.Type = enumResult.Name; } } results.Add(engineProperty); } return(results); } catch (Exception ex) { logger.Error(ex, $"The method {nameof(ReadProperties)} failed."); return(results); } }