/// <summary> /// Export the API to disk. /// See docs for more, lol. /// 1- /// 2- /// 3- /// /// end. /// </summary> /// <param name="path">Define the output path</param> /// <param name="pretty">Output readable JSON (Default: True)</param> public static void ExportPythonAPI(string path = null, bool pretty = true) { if (path == null) { path = DEFAULT_JSON_PATH; } String json_txt; DocContainer docs = GetPythonAPI(); if (pretty) { var options = new JsonSerializerSettings(); options.Formatting = Newtonsoft.Json.Formatting.Indented; json_txt = JsonConvert.SerializeObject(docs, options); } else { json_txt = JsonConvert.SerializeObject(docs); } File.WriteAllText(path, json_txt); }
public static DocContainer ReadClass(Type type, BindingFlags flags) { var result = new DocContainer(); var classKey = XMLKeyComposer.GetKey(type); var className = type.Name; var classSummary = XMLDocReader.GetDocumentation(type); result.classes.Add(new DocClass(classKey, className, classSummary)); // Methods var methods = type.GetMethods(flags); foreach (var method in methods) { // Skip: setter, getter, operator-overloader, etc if (method.IsSpecialName) { continue; } var methodKey = XMLKeyComposer.GetKey(method); var methodName = method.Name; var returnType = method.ReturnType.Name; var paramList = new List <DocMethodParam>(); var documentation = XMLDocReader.GetDocumentation(method); var methodSummary = XMLDocReader.ExtractXML(documentation, "summary"); if (HasTag(TAG_NODOC, methodSummary)) { continue; } var prms = method.GetParameters(); foreach (var prm in prms) { var paramName = prm.Name; var paramType = ParamType(prm); var defaultValue = (prm.DefaultValue != null ? prm.DefaultValue.ToString() : null); var paramSummary = XMLDocReader.GetDocumentation(prm); var param = new DocMethodParam(paramName, paramType, defaultValue, paramSummary); paramList.Add(param); } var mtd = new DocMethod(methodKey, className, methodName, returnType, methodSummary, paramList); if (HasTag(TAG_AUTOCOMPLETE, methodSummary)) { mtd.flagAutocomplete = true; } result.methods.Add(mtd); } // Properties var props = type.GetProperties(flags); foreach (var prop in props) { var propKey = XMLKeyComposer.GetKey(prop); var itemName = prop.Name; var propertyType = prop.PropertyType.Name; var propSummary = XMLDocReader.GetDocumentation(prop); var prt = new DocProperty(propKey, className, itemName, propertyType, propSummary); result.properties.Add(prt); } // Fields var fields = type.GetFields(flags); foreach (var field in fields) { var fieldKey = XMLKeyComposer.GetKey(field); var itemName = field.Name; var fieldType = field.FieldType.Name; var fieldSummary = XMLDocReader.GetDocumentation(field); var prt = new DocProperty(fieldKey, className, itemName, fieldType, fieldSummary); result.properties.Add(prt); } return(result); }
/// <summary> /// Use reflection to generete the Python API List /// </summary> public static DocContainer GetPythonAPI() { if (cachedDocs != null) { return(cachedDocs); } Misc.SendMessage("AutoDoc v0.01", 20); var docSections = new List <Type> { // Test typeof(AutoDoc), // API typeof(Misc), typeof(Item), typeof(Items), typeof(Mobile), typeof(Mobiles), typeof(Player), typeof(Spells), typeof(Gumps), typeof(Journal), typeof(Target), typeof(Statics), // API Agents typeof(AutoLoot), typeof(Scavenger), typeof(SellAgent), typeof(BuyAgent), typeof(Organizer), typeof(Dress), typeof(Friend), typeof(Restock), typeof(BandageHeal), typeof(PathFinding), typeof(DPSMeter), typeof(Timer), typeof(Vendor), // Other classes typeof(Point2D), typeof(Point3D), typeof(Tile), typeof(Property), typeof(PathFinding.Route), typeof(Items.Filter), typeof(Mobiles.Filter), typeof(HotKeyEvent), }; BindingFlags flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance; cachedDocs = new DocContainer(); foreach (var docSection in docSections) { var classDocs = AutoDoc.ReadClass(docSection, flags); cachedDocs.AddRange(classDocs); } return(cachedDocs); }