private static void WriteExamples(Type type) { object[] attrs = type.GetCustomAttributes(typeof(ExampleAttribute), true); if (attrs == null || attrs.Length == 0) { _writer.WriteElementString("command", "examples", null, null); } else { _writer.WriteStartElement("command", "examples", null); for (int i = 0; i < attrs.Length; i++) { ExampleAttribute ex = (ExampleAttribute)attrs[i]; _writer.WriteStartElement("command", "example", null); if (attrs.Length == 1) { _writer.WriteElementString("maml", "title", null, "------------------EXAMPLE------------------"); } else { _writer.WriteElementString("maml", "title", null, string.Format("------------------EXAMPLE {0}-----------------------", i + 1)); } _writer.WriteElementString("dev", "code", null, ex.Code); _writer.WriteStartElement("dev", "remarks", null); WritePara(ex.Remarks); _writer.WriteEndElement(); //dev:remarks _writer.WriteEndElement(); //command:example } _writer.WriteEndElement(); //command:examples } }
HelpExample GetExample(ExampleAttribute attribute) { var help = new HelpExample(); help.Example = attribute.Example; help.Description = attribute.Description; help.IsFile = attribute.IsFile; return(help); }
public async Task HelpAsync([Summary("The command to get help for.")][Remainder] string command) { SearchResult result = commandService.Search(Context, command); if (!result.IsSuccess) { _ = await Context.User.SendMessageAsync($"Sorry, I couldn't find a command like **{command}**.").ConfigureAwait(false); return; } string prefix = await commandManager.GetPrefixAsync(Context.Guild).ConfigureAwait(false); var builder = new EmbedBuilder { Color = new Color(114, 137, 218), Description = $"These are commands like **{command}**:" }; foreach (CommandMatch match in result.Commands) { CommandInfo cmd = match.Command; const string separator = ", "; var paramBuilder = new StringBuilder(); foreach (ParameterInfo param in cmd.Parameters) { _ = paramBuilder.Append(param.Name); if (!param.Summary.IsEmptyOrWhiteSpace()) { _ = paramBuilder.Append($" **({param.Summary})**"); } _ = paramBuilder.Append(separator); } string cmdParameters = paramBuilder.ToString().TrimEnd(separator.ToArray()); string description = $"Parameters: {cmdParameters}\n" + $"Remarks: {cmd.Remarks}"; ExampleAttribute example = cmd.Attributes.OfType <ExampleAttribute>().FirstOrDefault(); if (example != null && !example.ExampleText.IsEmpty()) { description += $"\nExample: {example.ExampleText}"; } _ = builder.AddField(x => { x.Name = string.Join(", ", cmd.Aliases); x.Value = description; x.IsInline = false; }); } _ = await Context.User.SendMessageAsync("", false, builder.Build()).ConfigureAwait(false); if (Context.Channel is IGuildChannel) { await ReplyAndDeleteAsync("I have sent you a private message").ConfigureAwait(false); } }
HelpExample GetExample(ExampleAttribute attribute) { var help = new HelpExample(); help.Example = attribute.ExampleCode; help.Description = GetLocalized(attribute.DescriptionKey); help.IsFile = attribute.IsFile; return(help); }
public static void Main() { using (FontRenderingAdvanced example = new FontRenderingAdvanced()) { // Get the title and category of this example using reflection. ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]); example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title); example.Run(30.0, 0.0); } }
public static void Main() { using (Textures example = new Textures()) { // Get the title and category of this example using reflection. ExampleAttribute info = ((ExampleAttribute)typeof(Textures).GetCustomAttributes(false)[0]); example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title); example.Run(30.0, 0.0); } }
public static void Main() { using (GameLoopForm example = new GameLoopForm()) { // Get the title and category of this example using reflection. ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]); example.Text = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title); example.ShowDialog(); } }
public void example_should_be_valid() { //arrange var label = new ExampleAttribute("label"); //act var result = label.IsValid(null); //assert Assert.IsTrue(result); }
static void Main() { // The 'using' idiom guarantees proper resource cleanup. // We request 30 UpdateFrame events per second, and unlimited // RenderFrame events (as fast as the computer can handle). using (Picking example = new Picking()) { // Get the title and category of this example using reflection. ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]); example.Title = String.Format("OpenTK | {0} {1}: {2} (use the mouse to pick)", info.Category, info.Difficulty, info.Title); example.Run(30.0); } }
/// <summary> /// Called when the tutorials namespace changes /// </summary> protected void OnTutorialNamespaceChanged() { Type[] types = typeof(TutorialsView).Assembly.GetTypes(); tutorialsTree.Nodes.Clear(); tutorialsTree.ShowNodeToolTips = true; foreach (Type t in types) { if (t.Namespace != namespce) { continue; } if (t.GetMethod("Run") == null) { continue; } string category = "Examples"; ExampleAttribute exa = GetExampleAttribute(t); if (exa != null) { category = exa.Category; } TreeNode par = null; foreach (TreeNode nd in tutorialsTree.Nodes) { if (category.Equals(nd.Tag)) { par = nd; } } if (par == null) { par = tutorialsTree.Nodes.Add(category); par.Tag = category; par.NodeFont = new Font(tutorialsTree.Font, FontStyle.Bold); par.Text = category; } string name = t.Name; TreeNode nd2 = par.Nodes.Add(name); if (exa != null) { nd2.ToolTipText = exa.Description; } nd2.Tag = t; } tutorialsTree.ExpandAll(); if ((tutorialsTree.Nodes.Count > 0) && (tutorialsTree.Nodes[0].Nodes.Count > 0)) { tutorialsTree.SelectedNode = tutorialsTree.Nodes[0].Nodes[0]; } }
protected void OnSelectionChanged() { Type tutorialClass = SelectedTutorial; if (tutorialClass == null) { return; } exampleSummaryBox.Clear(); exampleSummaryBox.SelectionColor = Color.DarkBlue; exampleSummaryBox.SelectionFont = new Font(FontFamily.GenericSansSerif, 11f, FontStyle.Bold); exampleSummaryBox.AppendText(tutorialClass.Name + Environment.NewLine); //label1.Text = "'" + tutorialClass.Name + "' source code"; ExampleAttribute exa = GetExampleAttribute(tutorialClass); exampleSummaryBox.SelectionFont = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular); exampleSummaryBox.SelectionColor = Color.FromArgb(0, 0, 100); string desc = ""; if (exa != null) { desc = exa.Description; } exampleSummaryBox.AppendText(desc); exampleSummaryBox.Refresh(); string filename = GetSourceCodeFilename(tutorialClass); sourceTextBox.Clear(); if (filename == null) { sourceTextBox.AppendText("Tutorial source code was not found. " + Environment.NewLine + "Go to the properties of the source file in Visual Studio and set 'Copy To Output Directory' to 'Copy if newer'."); return; } StreamReader sr = new StreamReader(filename); while (true) { string line = sr.ReadLine(); if (line == null) { break; } PrettyPrint(line); } sr.Close(); this.PerformLayout(); }
public TagGroupDocumentation(ResourceKeyStack messagePath, ITagGroup tagGroup, IList <Func <ITag, TagDocumentation, bool> > specials, Dictionary <int, TagDocumentation> tagDictionary) { _messagePath = messagePath.BranchFor(tagGroup); _name = tagGroup.Name; _specials = specials; _tagDictionary = tagDictionary; _tags = new List <int>(); var tagGroupType = tagGroup.GetType(); _description = DescriptionAttribute.Harvest(tagGroupType) ?? _messagePath.Description; _title = TitleAttribute.HarvestTagLibrary(tagGroupType); foreach (ITag _tag in tagGroup) { var hash = _tag.GetType().GetHashCode(); if (!_tagDictionary.ContainsKey(hash)) { _tagDictionary[hash] = null; var tagDoc = new TagDocumentation(_messagePath, _tag, _specials, _tagDictionary); _tagDictionary[hash] = tagDoc; } _tags.Add(hash); } if (ExampleAttribute.Harvest(tagGroupType)) { _examples.AddRange(ExampleAttribute.HarvestTags(tagGroupType)); } if (HasExample.Has(tagGroupType)) { _examples.Add(new ExampleAttribute(_messagePath.Example)); } if (NoteAttribute.Harvest(tagGroupType)) { _notes.AddRange(NoteAttribute.HarvestTags(tagGroupType)); } if (HasNote.Has(tagGroupType)) { _notes.Add(new NoteAttribute(_messagePath.Note)); } }
// Use this for initialization void Start() { List <AttributesSystem.attributes.Attribute> attributes = new List <AttributesSystem.attributes.Attribute>(); PlayerData pData = new PlayerData(); ExampleAttribute atex = new ExampleAttribute(); atex.Init(1, 1, 100, 1, GameEnums.Modifier.ADDITION); attributes.Add(atex); pData.Init(1, attributes); ExampleAttribute atexModifier = new ExampleAttribute(); atexModifier.Init(2, 2, 2, 1, GameEnums.Modifier.ADDITION); Modifier _m = new Modifier(1, GameEnums.Modifier.ADDITION, atexModifier); pData.AddModifier(_m); _ExampleAttribute = pData.GetAttributeTotalValue <ExampleAttribute>(); }
public void Constructor_SetsValues() { var exampleAttribute = new ExampleAttribute("ExampleName"); Assert.That(exampleAttribute.Name, Is.EqualTo("ExampleName")); }
public ExampleAttribute(ExampleAttribute attribute) { Init(attribute.Value, attribute.MinValue, attribute.MaxValue, attribute.IncreaseStep, attribute.Modifier); }
public TagDocumentation(ResourceKeyStack messagePath, ITag tag, IList <Func <ITag, TagDocumentation, bool> > specials, Dictionary <int, TagDocumentation> tagDictionary) { _tagDictionary = tagDictionary; _messagePath = messagePath.BranchFor(tag); _name = tag.TagName; var tagType = tag.GetType(); _category = CategoryHelper.GetCategory(tagType); _list = new List <PropertyDocumentation>(); _nested = new List <int>(); _methods = new List <FunctionDocumentation>(); TagBodyMode = tag.TagBodyMode; foreach (var property in tagType.GetCustomAttributes <PropertyAttribute>()) { _list.Add(new PropertyDocumentation(_messagePath, property)); } foreach (var property in tagType.GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.FlattenHierarchy)) { if (Equals(property.PropertyType, typeof(ITagAttribute)) && !IsInternal(property)) { _list.Add(new PropertyDocumentation(_messagePath, property)); } } var extendingTag = tag as ITagExtendTagLib; if (extendingTag != null) { foreach (var nested in extendingTag.TagLibExtension) { var hash = nested.GetType().GetHashCode(); if (!_tagDictionary.ContainsKey(hash)) { _tagDictionary[hash] = null; var tagDoc = new TagDocumentation(_messagePath, nested, specials, _tagDictionary); _tagDictionary[hash] = tagDoc; } _nested.Add(hash); } } var instanceDocumentation = tag as IInstanceTagDocumentation; if (instanceDocumentation != null) { _description = instanceDocumentation.Description; _examples.AddRange(instanceDocumentation.Examples ?? new ExampleAttribute[] {}); _notes.AddRange(instanceDocumentation.Notes ?? new NoteAttribute[] {}); } else { _description = DescriptionAttribute.Harvest(tagType) ?? _messagePath.Description; if (ExampleAttribute.Harvest(tagType)) { _examples.AddRange(ExampleAttribute.HarvestTags(tagType)); } if (HasExample.Has(tagType)) { _examples.Add(new ExampleAttribute(_messagePath.Example)); } if (NoteAttribute.Harvest(tagType)) { _notes.AddRange(NoteAttribute.HarvestTags(tagType)); } if (HasNote.Has(tagType)) { _notes.Add(new NoteAttribute(_messagePath.Note)); } } }
public async Task HelpHandling(string lookup, int index = 1, bool exact = false) { try { List <CommandInfo> commListE = Program.XuCommand.Commands.ToList(); // List<ModuleInfo> moduleListE = Program.XuCommand.Modules.ToList(); commListE = commListE.FindAll(ci => ci.Name == lookup.Split(' ').Last()); List <CommandInfo> commList = commListE; if (exact) { commList = new List <CommandInfo>(); foreach (var item in commListE) { foreach (var alias in item.Aliases) { if (alias == lookup) { commList.Add(item); //item.Attributes.Contains(new DeprecatedAttribute()); } } } } int allMatches = commList.Count; CommandInfo comm; try { comm = commList[index - 1]; } catch (ArgumentOutOfRangeException e) { //not a command GroupHandling(lookup); return; } string allAlias = ""; IReadOnlyList <string> aliases = comm.Aliases ?? new List <string>(); string trueName = comm.Name; if (aliases.ToList().Find(al => al == lookup) == lookup) { trueName = lookup; } if (aliases.Count != 0) { foreach (string alias in comm.Aliases) { allAlias += alias + "\n"; } } string allPara = "No parameters."; string examplePara = ""; IReadOnlyList <ParameterInfo> @params = comm.Parameters.ToList(); if (@params.Count != 0) { allPara = ""; foreach (var para in comm.Parameters) { allPara += (para.IsMultiple ? "params " : "") + Util.String.SimplifyTypes(para.Type.ToString()) + " " + para.Name + (para.IsOptional ? " (optional) // default value = " + para.DefaultValue : "") + "\n"; examplePara += para.Name + " "; } } string trueSummary = "No summary given."; if (comm.Summary != null) { trueSummary = comm.Summary; } bool dep = comm.Attributes.Contains(new DeprecatedAttribute()) || comm.Module.Attributes.Contains(new DeprecatedAttribute()); string nsfwPossibility = comm.Attributes.Count(x => x is NsfwPossibilityAttribute) > 0 ? (comm.Attributes.First(x => x is NsfwPossibilityAttribute) as NsfwPossibilityAttribute).Warnings : ""; nsfwPossibility += comm.Module.Attributes.Count(x => x is NsfwPossibilityAttribute) > 0 ? "Group-wide:\n\n" + (comm.Module.Attributes.First(x => x is NsfwPossibilityAttribute) as NsfwPossibilityAttribute).Warnings : ""; if (comm.Attributes.Count(x => x is ExampleAttribute) > 0) { ExampleAttribute ex = comm.Attributes.First(x => x is ExampleAttribute) as ExampleAttribute; if (ex.ExampleParameters != "") { examplePara = ex.ExampleParameters; } examplePara += ex.AttachmentNeeded ? "\n\n[You need to upload a file to use this.]" : ""; } string exampleUsage = $"{Program.prefix}{trueName} " + examplePara; EmbedBuilder embed = Util.Embed.GetDefaultEmbed(Context, "Help", $"The newer *better* help. Showing result #{index} out of {allMatches} match(s).", Color.Magenta); embed.Fields = new List <EmbedFieldBuilder> { new() { Name = "Command Name", Value = $"`{trueName}`", IsInline = true }, new() { Name = "Summary", Value = trueSummary, IsInline = true }, new() { Name = "Known Aliases", Value = $"```\n{allAlias}```", IsInline = false }, new() { Name = "Parameters", Value = $"```cs\n{allPara}```", IsInline = true }, new() { Name = "Example Usage", Value = $"`{exampleUsage}`", IsInline = false } }; if (dep) { embed.Fields.Add(new EmbedFieldBuilder { Name = "Deprecated", Value = "__**All commands in this group are deprecated. They are going to be removed in a future update.**__", IsInline = true }); } if (nsfwPossibility != "") { embed.Fields.Add(new EmbedFieldBuilder { Name = "NSFW Possibility", Value = $"This can show NSFW content. NSFW content is restricted to NSFW channels.\n**{nsfwPossibility}**", IsInline = true }); } await ReplyAsync("", false, embed.Build()); } catch (Exception e) { await Util.Error.BuildError(e, Context); } }