Exemplo n.º 1
0
        private static void ParseControlAttributes(ConsoleControl control, ParserContext context)
        {
            foreach (var attribute in context.CurrentElement.Attributes)
            {
                var extensions = control.GetType().Attrs <MarkupExtensionAttribute>().Where(a => a.AttributeName == attribute.Name);

                if (extensions.Count() > 1)
                {
                    throw new InvalidOperationException("More than 1 extension registered for property " + attribute.Name);
                }
                else if (extensions.Count() == 1)
                {
                    extensions.First().Processor.Process(context);
                }
                else
                {
                    var propertyInfo = control.GetType().GetProperty(attribute.Name);
                    var methodInfo   = control.GetType().GetMethod(attribute.Name);
                    if (propertyInfo.GetGetMethod() == null || propertyInfo.GetSetMethod() == null)
                    {
                        if (propertyInfo.PropertyType == typeof(Event))
                        {
                            // there is special handling for events downstream so let this through
                        }
                        else
                        {
                            throw new InvalidOperationException($"Property {control.GetType().FullName}.{attribute.Name} does not have a public getter and setter");
                        }
                    }

                    SetPropertyFromTextValue(context, control, propertyInfo, attribute.Value);
                }
            }
        }
Exemplo n.º 2
0
        public static ViewModelBinding OneWayBind <TControlPropertyType, TDataPropertyType>(ConsoleControl control, string propertyName, ObservableObject viewModel, string observablePath, Func <TDataPropertyType, TControlPropertyType> map)
        {
            ViewModelBinding ret = new ViewModelBinding(control, control.GetType().GetProperty(propertyName), viewModel, observablePath, (v) =>
            {
                return(map((TDataPropertyType)v));
            }, null);

            return(ret);
        }
Exemplo n.º 3
0
 public ViewModelBinding(ConsoleControl control, string propertyName, ObservableObject viewModel, string observablePath) : this(control, control.GetType().GetProperty(propertyName), viewModel, observablePath)
 {
 }
Exemplo n.º 4
0
        private static void ParseControlAttributes(ConsoleControl control, ParserContext context)
        {
            foreach (var attribute in context.CurrentElement.Attributes)
            {
                var extensions = control.GetType().Attrs<MarkupExtensionAttribute>().Where(a => a.AttributeName == attribute.Name);

                if(extensions.Count() > 1)
                {
                    throw new InvalidOperationException("More than 1 extension registered for property "+attribute.Name);
                }
                else if(extensions.Count() == 1)
                {
                    extensions.First().Processor.Process(context);
                }
                else
                {
                    var propertyInfo = control.GetType().GetProperty(attribute.Name);
                    var methodInfo = control.GetType().GetMethod(attribute.Name);
                    if (propertyInfo.GetGetMethod() == null || propertyInfo.GetSetMethod() == null)
                    {
                        if (propertyInfo.PropertyType == typeof(Event))
                        {
                            // there is special handling for events downstream so let this through
                        }
                        else
                        {
                            throw new InvalidOperationException($"Property {control.GetType().FullName}.{attribute.Name} does not have a public getter and setter");
                        }
                    }

                    SetPropertyFromTextValue(context, control, propertyInfo, attribute.Value);
                }
            }
        }