public async Task AjudaCmd(CommandContext ctx, [Description("Comando que você precisa de ajuda")] params string[] comando) { if (comando.Length == 0) { DiscordEmbedBuilder builder = new DiscordEmbedBuilder { Color = DiscordColor.Purple, ImageUrl = "https://i.imgur.com/mQVFSrP.gif", Title = "Comandos atacaaaaar 😁" }; Type[] types = typeof(Kurosawa).Assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { StringBuilder sb = new StringBuilder(); Modulo moduleAttr = types[i].GetCustomAttribute <Modulo>(); if (moduleAttr != null) { GroupAttribute grupo = types[i].GetCustomAttribute <GroupAttribute>(); if (grupo == null) { MethodInfo[] metodos = types[i].GetMethods(); for (int j = 0; j < metodos.Length; j++) { CommandAttribute comandoAtributo = metodos[j].GetCustomAttribute <CommandAttribute>(); HiddenAttribute comandoHidden = metodos[j].GetCustomAttribute <HiddenAttribute>(); if (comandoAtributo != null && comandoHidden == null) { sb.Append($"`{comandoAtributo.Name}` "); } } } else { sb.Append($"`{grupo.Name}` "); } DescriptionAttribute descricao = types[i].GetCustomAttribute <DescriptionAttribute>(); builder.AddField($"**{moduleAttr.Nome}** {$" {moduleAttr.Icon}" ?? ""}- *{descricao.Description}*", sb.ToString(), false); } } builder.WithDescription("Para mais informações sobre um módulo ou comando, digite `help {Comando}` que eu lhe informarei mais sobre ele 😄"); await ctx.RespondAsync(embed : builder.Build()); } else { await ctx.Client.GetCommandsNext().DefaultHelpAsync(ctx, comando); } }
/// <summary> /// Gets all objects referenced by <paramref name="obj" /> potentially marked with the <paramref name="hidden" /> attribute. /// </summary> /// <param name="obj">The object the referenced objects should be returned for.</param> /// <param name="mode">The serialization mode that should be used to serialize the objects.</param> /// <param name="hidden">The <see cref="HiddenAttribute" /> instance, if any, the field storing <paramref name="obj" /> was marked with.</param> protected internal override IEnumerable<object> GetReferencedObjects(object obj, SerializationMode mode, HiddenAttribute hidden) { // Optimization: Skip enumerables with hidden elements if (mode == SerializationMode.Optimized && hidden?.HideElements == true) { // We have to make sure the objects referenced by the list are discovered nevertheless var enumerable = obj as IEnumerable; if (enumerable == null) yield break; foreach (var element in enumerable.Cast<object>().Where(item => item.GetType().IsReferenceType())) yield return element; } else yield return obj; }
private static IHiddenFacet Create(HiddenAttribute attribute, ISpecification holder) { return(attribute == null ? null : new HiddenFacet(attribute.Value, holder)); }
/// <summary> /// Gets all objects referenced by <paramref name="obj" /> potentially marked with the <paramref name="hidden" /> attribute. /// </summary> /// <param name="obj">The object the referenced objects should be returned for.</param> /// <param name="mode">The serialization mode that should be used to serialize the objects.</param> /// <param name="hidden">The <see cref="HiddenAttribute" /> instance, if any, the field storing <paramref name="obj" /> was marked with.</param> protected internal override IEnumerable <object> GetReferencedObjects(object obj, SerializationMode mode, HiddenAttribute hidden) { // Optimization: Skip enumerables with hidden elements if (mode == SerializationMode.Optimized && hidden?.HideElements == true) { // We have to make sure the objects referenced by the list are discovered nevertheless var enumerable = obj as IEnumerable; if (enumerable == null) { yield break; } foreach (var element in enumerable.Cast <object>().Where(item => item.GetType().IsReferenceType())) { yield return(element); } } else { yield return(obj); } }
private static bool IsHidden(this FieldInfo enumField) { HiddenAttribute hiddenAttrib = enumField.GetAttribute <HiddenAttribute>(); return(hiddenAttrib != null && !hiddenAttrib.Visible); }
public static bool IsHidden <T>(this T source) { HiddenAttribute attribute = GetHiddenAttribute(source); return(attribute != null && attribute.IsHidden); }
/// <summary> /// Gets all objects referenced by <paramref name="obj" /> potentially marked with the <paramref name="hidden" /> attribute. /// </summary> /// <param name="obj">The object the referenced objects should be returned for.</param> /// <param name="mode">The serialization mode that should be used to serialize the objects.</param> /// <param name="hidden"> /// The <see cref="HiddenAttribute" /> instance, if any, the field storing <paramref name="obj" /> was /// marked with. /// </param> protected internal override IEnumerable<object> GetReferencedObjects(object obj, SerializationMode mode, HiddenAttribute hidden) { // Optimization: Skip arrays with hidden elements if (mode == SerializationMode.Optimized && hidden?.HideElements == true) { // We have to make sure the objects referenced by the array are discovered nevertheless if (!obj.GetType().GetElementType().IsReferenceType()) yield break; foreach (var element in (object[])obj) yield return element; } else yield return obj; }
/// <summary> /// Gets all objects referenced by <paramref name="obj" /> potentially marked with the <paramref name="hidden" /> attribute. /// </summary> /// <param name="obj">The object the referenced objects should be returned for.</param> /// <param name="mode">The serialization mode that should be used to serialize the objects.</param> /// <param name="hidden"> /// The <see cref="HiddenAttribute" /> instance, if any, the field storing <paramref name="obj" /> was /// marked with. /// </param> protected internal override IEnumerable <object> GetReferencedObjects(object obj, SerializationMode mode, HiddenAttribute hidden) { // Optimization: Skip arrays with hidden elements if (mode == SerializationMode.Optimized && hidden?.HideElements == true) { // We have to make sure the objects referenced by the array are discovered nevertheless if (!obj.GetType().GetElementType().IsReferenceType()) { yield break; } foreach (var element in (object[])obj) { yield return(element); } } else { yield return(obj); } }
private static void BuildControl(Form form, PropertyInfo property, TheSettings theSettings) { Control control = null; object[] attributes = property.GetCustomAttributes(false); MusicPlugin.Code.Attributes.DescriptionAttribute descriptionAttribute = attributes.Select(x => x as MusicPlugin.Code.Attributes.DescriptionAttribute).Where(i => i != null).First();; ControlAttribute controlAttribute = attributes.Select(x => x as ControlAttribute).Where(i => i != null).First(); HiddenAttribute hiddenAttribute = attributes.Select(x => x as HiddenAttribute).Where(i => i != null).First(); GroupAttribute groupAttribute = attributes.Select(x => x as GroupAttribute).Where(i => i != null).First(); if (hiddenAttribute != null) { if (hiddenAttribute.Hidden) { return; } } GroupBox groupBox = null; TableLayoutPanel tableLayoutPanel = null; if (controlAttribute != null) { if (form.Controls[groupAttribute.Group + "GroupBoxPanel"] != null) { groupBox = (GroupBox)form.Controls[groupAttribute.Group + "GroupBoxPanel"].Controls[groupAttribute.Group + "GroupBox"]; tableLayoutPanel = (TableLayoutPanel)groupBox.Controls[0]; } else { Panel panel = new Panel() { Padding = new Padding(0, 5, 0, 5), Name = groupAttribute.Group + "GroupBoxPanel", AutoSize = true, Dock = DockStyle.Top }; groupBox = new GroupBox() { FlatStyle = FlatStyle.Flat, Text = groupAttribute.Group, Name = groupAttribute.Group + "GroupBox", AutoSize = true, Dock = DockStyle.Fill }; panel.Controls.Add(groupBox); tableLayoutPanel = new TableLayoutPanel() { ColumnCount = 2, Dock = DockStyle.Fill, AutoSize = true }; tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent) { Width = 45 }); tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent) { Width = 55 }); groupBox.Controls.Add(tableLayoutPanel); form.Controls.Add(panel); } if (controlAttribute.Control.Equals(typeof(CheckBox))) { control = new CheckBox() { FlatStyle = FlatStyle.Flat, Checked = (bool)property.GetValue(theSettings, null), Name = property.Name }; (control as CheckBox).CheckedChanged += new EventHandler(ConfigureView_Changed); } else if (controlAttribute.Control.Equals(typeof(FolderTextBox))) { control = new FolderTextBox() { Text = (string)property.GetValue(theSettings, null), Name = property.Name }; (control as FolderTextBox).TextChanged += new EventHandler(ConfigureView_Changed); } else if (controlAttribute.Control.Equals(typeof(FileTextBox))) { control = new FileTextBox() { Text = (string)property.GetValue(theSettings, null), Name = property.Name }; (control as FileTextBox).TextChanged += new EventHandler(ConfigureView_Changed); ExtAttribute extAttribute = attributes.Select(x => x as ExtAttribute).Where(i => i != null).First(); (control as FileTextBox).Ext = extAttribute.Ext; } else if (controlAttribute.Control.Equals(typeof(TextBox))) { control = new TextBox() { BorderStyle = BorderStyle.FixedSingle, Text = (string)property.GetValue(theSettings, null), Name = property.Name, Width = 200 }; (control as TextBox).TextChanged += new EventHandler(ConfigureView_Changed); } } else { return; } tableLayoutPanel.Controls.Add(new Label() { Text = descriptionAttribute.Description, AutoSize = true, Anchor = AnchorStyles.Right }); tableLayoutPanel.Controls.Add(control); _controlBindings.Add(control, property); }
public static bool IsHidden <T>(this T source, string name) { HiddenAttribute attribute = source.GetHiddenAttribute(name); return(attribute != null && attribute.IsHidden); }
/// <summary> /// Gets all objects referenced by <paramref name="obj" /> potentially marked with the <paramref name="hidden" /> attribute. /// </summary> /// <param name="obj">The object the referenced objects should be returned for.</param> /// <param name="mode">The serialization mode that should be used to serialize the objects.</param> /// <param name="hidden">The <see cref="HiddenAttribute" /> instance, if any, the field storing <paramref name="obj" /> was marked with.</param> protected internal virtual IEnumerable<object> GetReferencedObjects(object obj, SerializationMode mode, HiddenAttribute hidden) { yield return obj; }
private static IHiddenFacet Create(HiddenAttribute attribute, ISpecification holder) => attribute is null ? null : new HiddenFacet(WhenTo.Always, holder);
private static void Process(HiddenAttribute attribute, ISpecification specification) => FacetUtils.AddFacet(Create(attribute, specification));