Beispiel #1
0
        private static ICommand TryGetCommand(ICommandProxy proxy, DependencyObject source, string name)
        {
            Contract.Requires(proxy != null);
            Contract.Requires(source != null);
            Contract.Requires(!name.IsNullOrWhiteSpace());

            var realSource = proxy.GetCommandOwner(source);

            if (realSource != null)
            {
                var propInfo = (from property in realSource.GetType().GetProperties()
                                where property.CanRead
                                where property.Name == name
                                where typeof(ICommand).IsAssignableFrom(property.PropertyType)
                                select property).SingleOrDefault();

                if (propInfo != null)
                {
                    return((ICommand)propInfo.GetGetMethod().Invoke(realSource, new object[0]));
                }
            }
            return(null);
        }
Beispiel #2
0
        private static ICommand TryGetCommand(ICommandProxy proxy, DependencyObject source, string name)
        {
            Contract.Requires(proxy != null);
            Contract.Requires(source != null);
            Contract.Requires(!name.IsNullOrWhiteSpace());

            var realSource = proxy.GetCommandOwner(source);
            if (realSource != null)
            {
                var propInfo = (from property in realSource.GetType().GetProperties()
                                where property.CanRead
                                where property.Name == name
                                where typeof(ICommand).IsAssignableFrom(property.PropertyType)
                                select property).SingleOrDefault();

                if (propInfo != null)
                {
                    return (ICommand)propInfo.GetGetMethod().Invoke(realSource, new object[0]);
                }
            }
            return null;
        }