本文整理汇总了C#中AddIn.FindType方法的典型用法代码示例。如果您正苦于以下问题:C# AddIn.FindType方法的具体用法?C# AddIn.FindType怎么用?C# AddIn.FindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AddIn
的用法示例。
在下文中一共展示了AddIn.FindType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRegisteredCommand
/// <summary>
/// Gets a known WPF command.
/// </summary>
/// <param name="addIn">The addIn definition that defines the command class.</param>
/// <param name="commandName">The name of the command, e.g. "Copy".</param>
/// <returns>The WPF ICommand with the given name, or null if thecommand was not found.</returns>
public static System.Windows.Input.ICommand GetRegisteredCommand(AddIn addIn, string commandName)
{
if (addIn == null)
throw new ArgumentNullException("addIn");
if (commandName == null)
throw new ArgumentNullException("commandName");
System.Windows.Input.ICommand command;
lock (knownCommands) {
if (knownCommands.TryGetValue(commandName, out command))
return command;
}
int pos = commandName.LastIndexOf('.');
if (pos > 0) {
string className = commandName.Substring(0, pos);
string propertyName = commandName.Substring(pos + 1);
Type classType = addIn.FindType(className);
if (classType != null) {
PropertyInfo p = classType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Static);
if (p != null)
return (System.Windows.Input.ICommand)p.GetValue(null, null);
FieldInfo f = classType.GetField(propertyName, BindingFlags.Public | BindingFlags.Static);
if (f != null)
return (System.Windows.Input.ICommand)f.GetValue(null);
}
}
return null;
}