/// <summary> /// Processes a type that implements the ICommand interface, it detects various special attributes to determine /// if they should appear in the generated list of commands that can be added to the toolPanel. /// </summary> /// <param name="t">The type to process.</param> private void ProcessICommandType(Type t) { AddBehaviorItem cmd = GetICommandAttributes(t); // If it assumed that a command MUST have the DisplayName attribute properly assigned and thus we consider // these valid items for our generated list. if (!String.IsNullOrEmpty(cmd.Name)) { // If the command does not specify a category, then group all of these into the "Uncategorized" category // so they are grouped together if (String.IsNullOrEmpty(cmd.Category)) { cmd.Category = "Uncategorized"; } // Store the type in the object so it can be dynamically created when needed later cmd.BehaviorType = t; addItems.Add(cmd); } }
internal static AddBehaviorItem GetICommandAttributes(Type t) { // Get all custom attributes associated with this type but do not gather those that might be obtained // via inheritance. object[] attrs = t.GetCustomAttributes(false); // Create object to store information AddBehaviorItem cmd = new AddBehaviorItem(); // Process each attribute, looking for the ones we care about and if found, extract information and continue // to the next attribute. foreach (object att in attrs) { ESRI.ArcGIS.Client.Extensibility.CategoryAttribute catAttribute = att as ESRI.ArcGIS.Client.Extensibility.CategoryAttribute; if (catAttribute != null) { cmd.Category = catAttribute.Category; continue; } ESRI.ArcGIS.Client.Extensibility.DisplayNameAttribute nameAttribute = att as ESRI.ArcGIS.Client.Extensibility.DisplayNameAttribute; if (nameAttribute != null) { cmd.Name = nameAttribute.Name; continue; } ESRI.ArcGIS.Client.Extensibility.DescriptionAttribute descAttribute = att as ESRI.ArcGIS.Client.Extensibility.DescriptionAttribute; if (descAttribute != null) { cmd.Description = descAttribute.Description; continue; } } return(cmd); }
internal static AddBehaviorItem GetICommandAttributes(Type t) { // Get all custom attributes associated with this type but do not gather those that might be obtained // via inheritance. object[] attrs = t.GetCustomAttributes(false); // Create object to store information AddBehaviorItem cmd = new AddBehaviorItem(); // Process each attribute, looking for the ones we care about and if found, extract information and continue // to the next attribute. foreach (object att in attrs) { ESRI.ArcGIS.Client.Extensibility.CategoryAttribute catAttribute = att as ESRI.ArcGIS.Client.Extensibility.CategoryAttribute; if (catAttribute != null) { cmd.Category = catAttribute.Category; continue; } ESRI.ArcGIS.Client.Extensibility.DisplayNameAttribute nameAttribute = att as ESRI.ArcGIS.Client.Extensibility.DisplayNameAttribute; if (nameAttribute != null) { cmd.Name = nameAttribute.Name; continue; } ESRI.ArcGIS.Client.Extensibility.DescriptionAttribute descAttribute = att as ESRI.ArcGIS.Client.Extensibility.DescriptionAttribute; if (descAttribute != null) { cmd.Description = descAttribute.Description; continue; } } return cmd; }