Ejemplo n.º 1
0
        protected virtual void OnEventRaised(object sender, EventArgs eventArgs)
        {
            if (Command == null)
            {
                return;
            }

            var parameter = CommandParameter;

            if (parameter == null && !string.IsNullOrEmpty(EventArgsParameterPath))
            {
                //Walk the ParameterPath for nested properties.
                var    propertyPathParts = EventArgsParameterPath.Split('.');
                object propertyValue     = eventArgs;
                foreach (var propertyPathPart in propertyPathParts)
                {
                    var propInfo = propertyValue.GetType().GetTypeInfo().GetDeclaredProperty(propertyPathPart);
                    propertyValue = propInfo.GetValue(propertyValue);
                }
                parameter = propertyValue;
            }

            if (parameter == null && eventArgs != null && eventArgs != EventArgs.Empty && EventArgsConverter != null)
            {
                parameter = EventArgsConverter.Convert(eventArgs, typeof(object), EventArgsConverterParameter,
                                                       CultureInfo.CurrentUICulture);
            }

            if (Command.CanExecute(parameter))
            {
                Command.Execute(parameter);
            }
        }
Ejemplo n.º 2
0
        protected virtual void OnEventRaised(object sender, EventArgs eventArgs)
        {
            if (Command == null)
            {
                return;
            }

            var parameter = CommandParameter;

            if (parameter == null && !string.IsNullOrEmpty(EventArgsParameterPath))
            {
                if (EventArgsParameterPath == ".")
                {
                    parameter = eventArgs;
                }
                else
                {
                    //Walk the ParameterPath for nested properties.
                    var    propertyPathParts = EventArgsParameterPath.Split('.');
                    object propertyValue     = eventArgs;
                    foreach (var propertyPathPart in propertyPathParts)
                    {
                        var propInfo = propertyValue.GetType().GetRuntimeProperty(propertyPathPart);
                        if (propInfo == null)
                        {
                            throw new MissingMemberException($"Unable to find {EventArgsParameterPath}");
                        }

                        propertyValue = propInfo.GetValue(propertyValue);
                        if (propertyValue == null)
                        {
                            break;
                        }
                    }
                    parameter = propertyValue;
                }
            }

            if (parameter == null && eventArgs != null && eventArgs != EventArgs.Empty && EventArgsConverter != null)
            {
                parameter = EventArgsConverter.Convert(eventArgs, typeof(object), EventArgsConverterParameter,
                                                       CultureInfo.CurrentUICulture);
            }

            if (Command.CanExecute(parameter))
            {
                Command.Execute(parameter);
            }
        }
Ejemplo n.º 3
0
        private object GetEventArgsPropertyPathValue(object parameter)
        {
            object commandParameter;
            object propertyValue = parameter;

            string[] propertyPathParts = EventArgsParameterPath.Split('.');
            foreach (string propertyPathPart in propertyPathParts)
            {
                PropertyInfo propInfo = propertyValue.GetType().GetProperty(propertyPathPart);
                propertyValue = propInfo.GetValue(propertyValue, null);
            }

            commandParameter = propertyValue;
            return(commandParameter);
        }