Пример #1
0
		/// <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;
		}
Пример #2
0
        private static ICommand GetCommandFromStaticProperty(AddIn addIn, string commandName)
        {
            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((ICommand)p.GetValue(null, null));
                    }
                    FieldInfo f = classType.GetField(propertyName, BindingFlags.Public | BindingFlags.Static);
                    if (f != null)
                    {
                        return((ICommand)f.GetValue(null));
                    }
                }
            }
            return(null);
        }
Пример #3
0
        /// <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);
        }