/// <summary> /// Parses method parameter model definitions within a JSON tree. /// </summary> /// <param name="root">The root of the JSON tree for the method.</param> /// <param name="api">The API model being constructed.</param> /// <returns>A list of method parameter models.</returns> static IEnumerable <ParameterModel> ParseFunctionParameters(JObject root, ApiModel api) { var results = new List <ParameterModel>(); JToken items; if (root.TryGetValue("parameters", out items)) { foreach (var item in items) { var key = (string)item["key"]; var type = api.FindType((string)item["type"]); var flags = ParseInterfaceMethodParameterFlags(item as JObject); JToken indirection; (item as JObject).TryGetValue("indirection", out indirection); JToken length; (item as JObject).TryGetValue("size", out length); results.Add(new ParameterModel( key, type, indirection != null ? (int)indirection : 0, flags, length != null ? (string)length : null )); } } return(results); }
/// <summary> /// Parses interface method model definitions within a JSON tree. /// </summary> /// <param name="root">The root of the JSON tree for the interface.</param> /// <param name="api">The API model being constructed.</param> /// <returns>A list of interface method models.</returns> static List <MethodModel> ParseInterfaceMethods(JObject root, ApiModel api) { var results = new List <MethodModel>(); JToken items; if (root.TryGetValue("methods", out items)) { foreach (var item in items) { var key = (string)item["key"]; var type = api.FindType((string)item["type"]); var index = int.Parse(item["index"].Value <string>()); var model = new MethodModel(api, key, type, index); foreach (var parameter in ParseFunctionParameters(item as JObject, api)) { model.AddParameter(parameter); } results.Add(model); } } return(results); }
/// <summary> /// Defines interfaces in an API model based on the contents of a JSON tree. /// </summary> /// <param name="root">The root of the JSON tree for the API.</param> /// <param name="api">The API model being constructed.</param> static void DefineInterfaces(JObject root, ApiModel api) { JToken items; if (root.TryGetValue("interfaces", out items)) { foreach (var item in items) { var key = (string)item["key"]; var model = (InterfaceModel)api.FindType(key); JToken parent = null; if ((item as JObject).TryGetValue("type", out parent)) { model.Parent = api.FindType((string)parent); } foreach (var method in ParseInterfaceMethods(item as JObject, api)) { model.AddMethod(method); } } } }
/// <summary> /// Defines structures in an API model based on the contents of a JSON tree. /// </summary> /// <param name="root">The root of the JSON tree for the API.</param> /// <param name="api">The API model being constructed.</param> static void DefineStructures(JObject root, ApiModel api) { JToken items; if (root.TryGetValue("structures", out items)) { foreach (var item in items) { var key = (string)item["key"]; var model = (StructureModel)api.FindType(key); foreach (var value in ParseStructureMembers(item as JObject, api)) { model.AddMember(value); } } } }
/// <summary> /// Parses structure member model definitions within a JSON tree. /// </summary> /// <param name="root">The root of the JSON tree for the structure.</param> /// <param name="api">The API model being constructed.</param> /// <returns>A list of structure member models.</returns> static List <StructureMemberModel> ParseStructureMembers(JObject root, ApiModel api) { var results = new List <StructureMemberModel>(); JToken items; if (root.TryGetValue("members", out items)) { foreach (var item in items) { var key = (string)item["key"]; var type = api.FindType((string)item["type"]); results.Add(new StructureMemberModel(key, type)); } } return(results); }
/// <summary> /// Parses function model definitions within a JSON tree. /// </summary> /// <param name="root">The root of the API JSON tree.</param> /// <param name="api">The API model being constructed.</param> static void ParseFunctions(JObject root, ApiModel api) { JToken items; if (root.TryGetValue("functions", out items)) { foreach (var item in items) { var key = (string)item["key"]; var type = api.FindType((string)item["type"]); var model = api.AddFunction(key, type); foreach (var parameter in ParseFunctionParameters(item as JObject, api)) { model.AddParameter(parameter); } } } }