It is easy to display a complete list of all commands in all loaded assemblies:
public string[] GetAllCommands()
{
return (
from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
from prop in type.GetProperties()
where
typeof(ICommand).IsAssignableFrom(prop.PropertyType) &&
prop.GetAccessors()[0].IsStatic
orderby type.Name, prop.Name
select type.Name + "." + prop.Name
).ToArray();
}
With PresentationFramework loaded I get the list at the bottom of this answer, which you will see is absolutely complete.
If you also want to see the command type (eg RoutedUIComand) and gestures, you can add this to the LINQ:
let commandType = prop.PropertyType
let gestures =
typeof(UIElement).IsAssignableFrom(commandType) ?
((UIElement)prop.GetValue(null)).InputGestures :
null
Then your select might be something like this:
select type.Name + "." + prop.Name + " " + commandType.Name + " " + gestures
Programmatically finding out which controls do something with a given command is also possible. Basically something like this ought to work (not tried, but this will give you the idea):
var allCommands = (
from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
from prop in type.GetProperties()
where
typeof(ICommand).IsAssignableFrom(prop.PropertyType) &&
prop.GetAccessors()[0].IsStatic
orderby type.Name, prop.Name
select new
{
typeName = type.Name,
propName = prop.Name,
displayAs = type.Name + "." + prop.Name,
}
).ToArray();
var classesReferencingCommand = (
from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
from method in type.GetMethods()
let methodBodyString = ConvertILToString(method.
answered 2009-11-06T22:56:57.030