Exemplo n.º 1
0
        public static IElementInitializer Create(IPropertyAdapter propertyAdapter, IEnumerable <object> values, XamlNamespaces namespaces)
        {
            if (!values.Any())
            {
                return(ElementInitializer.Empty);
            }

            if (ElementCollectionContentInitailizer.IsCollectionType(propertyAdapter.PropertyType) &&
                !(values.Count() == 1 && values.First() is XamlElement && propertyAdapter.PropertyType.IsAssignableFrom(((XamlElement)values.First()).GetElementType())))
            {
                IElementInitializer propertyContentInitializer = ElementCollectionContentInitailizer.Create(values, propertyAdapter.PropertyType);

                // wrap with a factory that creates the collection (when it's null) before adding its values
                return(new ElementPropertyMemberFactoryInitializer(propertyAdapter, propertyContentInitializer));
            }

            if (values.Count() == 1)
            {
                if (propertyAdapter.PropertyType == typeof(IFrameworkElementFactory))
                {
                    return(new FrameworkElementFactoryInitializer(propertyAdapter, ElementFactory.FromValue(values.First(), null, namespaces)));
                }

                IElementFactory contentFactory = ElementFactory.FromValue(values.First(), propertyAdapter.PropertyType, namespaces);
                return(new ElementPropertyMemberInitializer(propertyAdapter, contentFactory));
            }

            throw new Granular.Exception("Member of type \"{0}\" cannot have more than one child", propertyAdapter.PropertyType.Name);
        }
Exemplo n.º 2
0
            private static IElementFactory GetDeferredKeyFactory(XamlElement xamlElement)
            {
                Type elementType = xamlElement.GetElementType();

                IDeferredValueKeyProvider provider = DeferredValueKeyProviders.GetDeferredValueKeyProvider(elementType);

                if (provider != null)
                {
                    return(new DeferredKeyFactory(provider, xamlElement));
                }

                string keyPropertyName = DictionaryKeyPropertyAttribute.GetPropertyName(elementType);

                if (!keyPropertyName.IsNullOrWhiteSpace())
                {
                    XamlMember keyMember = xamlElement.Members.FirstOrDefault(member => member.Name.LocalName == keyPropertyName);
                    if (keyMember != null)
                    {
                        IPropertyAdapter keyProperty = PropertyAdapter.CreateAdapter(elementType, keyPropertyName);
                        return(ElementFactory.FromValue(keyMember.Values.Single(), keyProperty.PropertyType, xamlElement.Namespaces, xamlElement.SourceUri));
                    }
                }

                return(null);
            }
Exemplo n.º 3
0
        public PropertyDataEditor(IPropertyAdapter <TData, TValue> propertyAdapter,
                                  IEditorComponent <TValue> component,
                                  Func <string, TValidationState, string> propertyErrorProvider)
        {
            if (propertyAdapter == null)
            {
                throw new ArgumentNullException("propertyAdapter");
            }
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (propertyErrorProvider == null)
            {
                throw new ArgumentNullException("propertyErrorProvider");
            }

            _propertyAdapter       = propertyAdapter;
            _component             = component;
            _propertyErrorProvider = propertyErrorProvider;

            _component.ValueUpdated += OnComponentUpdatedValue;

            _component.SetReadOnly(_propertyAdapter.IsReadOnly);
        }
 public void Stub(IPropertyAdapter property)
 {
     var itemType = property.PropertyType.GetGenericArguments()[0];
     var list = CreateListOf(itemType);
     PopulateList(list, itemType);
     property.Stub(list);
 }
Exemplo n.º 5
0
        private static bool TryCreateAdapter(TypeMemberKey key, out IPropertyAdapter adapter)
        {
            adapter = null;

            if (key.MemberName.IsEmpty)
            {
                return(false);
            }

            DependencyProperty dependencyProperty = DependencyProperty.GetProperty(key.Type, key.MemberName);

            if (dependencyProperty != null)
            {
                adapter = new DependencyPropertyAdapter(dependencyProperty);
                return(true);
            }

            PropertyInfo clrProperty = GetClrProperty(key.Type, key.MemberName);

            if (clrProperty != null)
            {
                adapter = new ClrPropertyAdapter(clrProperty);
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyController"/> class.
 /// </summary>
 /// <param name="propertyAdapter">The property adapter.</param>
 public PropertyController(
     IPropertyAdapter propertyAdapter,
     ISearchAdapter searchAdapter)
 {
     this.propertyAdapter = propertyAdapter;
     this.searchAdapter = searchAdapter;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyController"/> class.
 /// </summary>
 /// <param name="propertyAdapter">The property adapter.</param>
 public PropertyController(
     IPropertyAdapter propertyAdapter,
     ISearchAdapter searchAdapter)
 {
     this.propertyAdapter = propertyAdapter;
     this.searchAdapter   = searchAdapter;
 }
        public void Stub(IPropertyAdapter property)
        {
            var itemType = property.PropertyType.GetGenericArguments()[0];
            var list     = CreateListOf(itemType);

            PopulateList(list, itemType);
            property.Stub(list);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderController"/> class.
 /// </summary>
 /// <param name="orderAdapter">The order adapter.</param>
 public OrderController(
     IOrderAdapter orderAdapter, 
     IPropertyAdapter propertyAdapter,
     IAuthAdapter authAdapter)
 {
     this.orderAdapter = orderAdapter;
     this.propertyAdapter = propertyAdapter;
     this.authAdapter = authAdapter;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderController"/> class.
 /// </summary>
 /// <param name="orderAdapter">The order adapter.</param>
 public OrderController(
     IOrderAdapter orderAdapter,
     IPropertyAdapter propertyAdapter,
     IAuthAdapter authAdapter)
 {
     this.orderAdapter    = orderAdapter;
     this.propertyAdapter = propertyAdapter;
     this.authAdapter     = authAdapter;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HomeController"/> class.
 /// </summary>
 public PropertyController(
     IAuthAdapter authAdapter,
     IPropertyFacade propertyFacade,
     IPropertyAdapter propertyAdapter)
 {
     this.authAdapter     = authAdapter;
     this.propertyFacade  = propertyFacade;
     this.propertyAdapter = propertyAdapter;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HomeController"/> class.
 /// </summary>
 public PropertyController(
     IAuthAdapter authAdapter,
     IPropertyFacade propertyFacade,
     IPropertyAdapter propertyAdapter)
 {
     this.authAdapter = authAdapter;
     this.propertyFacade = propertyFacade;
     this.propertyAdapter = propertyAdapter;
 }
Exemplo n.º 13
0
        static EditableStructMetadata()
        {
            TextProperty = new ValueTypeGenericPropertyAdapter <EditableStruct, string>(_ => _.Text, (t, v) =>
            {
                t.Text = v;
                return(t);
            });

            ReadonlyTextProperty = new ValueTypeGenericPropertyAdapter <EditableStruct, string>(_ => _.Text);
        }
Exemplo n.º 14
0
 public PropertyController(
     IPropertyAdapter propertyAdapter,
     ISearchAdapter searchAdapter,
     IAuthAdapter authAdapter,
     IListingAdapter listingAdapter)
 {
     this.propertyAdapter = propertyAdapter;
     this.searchAdapter   = searchAdapter;
     this.authAdapter     = authAdapter;
     this.listingAdapter  = listingAdapter;
 }
Exemplo n.º 15
0
        public PropertyController(
			IPropertyAdapter propertyAdapter,
			ISearchAdapter searchAdapter,
			IAuthAdapter authAdapter,
			IListingAdapter listingAdapter)
        {
            this.propertyAdapter = propertyAdapter;
            this.searchAdapter = searchAdapter;
            this.authAdapter = authAdapter;
            this.listingAdapter = listingAdapter;
        }
Exemplo n.º 16
0
        public ElementInitializer(XamlElement element)
        {
            elementType = element.GetElementType();
            namespaces  = element.Namespaces;

            memberInitializers = CreateMemberInitializers(element);
            contentInitializer = CreateContentInitializer(element);

            nameDirectiveValue = GetNameDirectiveValue(element);
            nameProperty       = GetNameProperty(element.GetElementType());
        }
Exemplo n.º 17
0
            public KeyValueElementFactory(Type keyType, IElementFactory valueFactory, XamlElement xamlElement)
            {
                this.valueFactory = valueFactory;

                keyProperty         = GetKeyProperty(valueFactory.ElementType);
                keyDirectiveFactory = GetKeyDirectiveFactory(xamlElement, keyType);

                if (keyDirectiveFactory == null && keyProperty == null)
                {
                    throw new Granular.Exception("Dictionary item \"{0}\" must have a key", xamlElement.Name);
                }
            }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ListingController"/> class.
 /// </summary>
 /// <param name="listingAdapter">The listing adapter.</param>
 public ListingController(
     IListingAdapter listingAdapter,
     IPropertyAdapter propertyAdapter,
     ISearchAdapter searchAdapter,
     IOrderAdapter orderAdapter,
     IFeaturedAdapter featuredAdapter,
     IListingFacade listingFacade)
 {
     this.listingAdapter  = listingAdapter;
     this.propertyAdapter = propertyAdapter;
     this.searchAdapter   = searchAdapter;
     this.orderAdapter    = orderAdapter;
     this.featuredAdapter = featuredAdapter;
     this.listingFacade   = listingFacade;
 }
Exemplo n.º 19
0
        internal PropertyMemento(object owner, bool cascade, IPropertyAdapter prop, IMementoFactory factory)
        {
            Property = prop;
            Owner    = Property.IsStatic ? null : owner;

            SavedValue = Property.GetValue(owner);

            Factory  = factory;
            Children = new List <ICompositeMemento>();

            if (cascade)
            {
                GenerateChildren();
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ListingController"/> class.
 /// </summary>
 /// <param name="listingAdapter">The listing adapter.</param>
 public ListingController(
     IListingAdapter listingAdapter,
     IPropertyAdapter propertyAdapter,
     ISearchAdapter searchAdapter,
     IOrderAdapter orderAdapter,
     IFeaturedAdapter featuredAdapter,
     IListingFacade listingFacade)
 {
     this.listingAdapter = listingAdapter;
     this.propertyAdapter = propertyAdapter;
     this.searchAdapter = searchAdapter;
     this.orderAdapter = orderAdapter;
     this.featuredAdapter = featuredAdapter;
     this.listingFacade = listingFacade;
 }
Exemplo n.º 21
0
        public ListDataEditor(Func <TItem, IDataEditor <TItem> > itemEditorFactory,
                              IPropertyAdapter <TData, IList <TItem> > propertyAdapter,
                              Func <TItem, TValidationState, TItemValidationState> itemValidityRetriever)
        {
            if (itemEditorFactory == null)
            {
                throw new ArgumentNullException("itemEditorFactory");
            }

            _itemEditorFactory     = itemEditorFactory;
            _propertyAdapter       = propertyAdapter;
            _itemValidityRetriever = itemValidityRetriever;

            ItemEditors = new ObservableCollection <IDataEditor <TItem> >();
        }
Exemplo n.º 22
0
 public ListingController(
     IPropertyAdapter propertyAdapter,
     ISearchAdapter searchAdapter,
     IAuthAdapter authAdapter,
     IListingAdapter listingAdapter,
     IFeaturedAdapter featuredAdapter,
     IPropertyFacade propertyFacade)
 {
     this.propertyAdapter = propertyAdapter;
     this.searchAdapter   = searchAdapter;
     this.authAdapter     = authAdapter;
     this.listingAdapter  = listingAdapter;
     this.featuredAdapter = featuredAdapter;
     this.propertyFacade  = propertyFacade;
 }
Exemplo n.º 23
0
        public ListingController(
			IPropertyAdapter propertyAdapter,
			ISearchAdapter searchAdapter,
			IAuthAdapter authAdapter,
			IListingAdapter listingAdapter,
			IFeaturedAdapter featuredAdapter,
			IPropertyFacade propertyFacade)
        {
            this.propertyAdapter = propertyAdapter;
            this.searchAdapter = searchAdapter;
            this.authAdapter = authAdapter;
            this.listingAdapter = listingAdapter;
            this.featuredAdapter = featuredAdapter;
            this.propertyFacade = propertyFacade;
        }
Exemplo n.º 24
0
        public static IElementInitializer Create(XamlName memberName, Type containingType, IEnumerable <object> values, XamlNamespaces namespaces)
        {
            IEventAdapter eventAdapter = EventAdapter.CreateAdapter(containingType, memberName);

            if (eventAdapter != null)
            {
                return(new ElementEventMemberInitializer(eventAdapter, GetEventHandlerName(memberName, values)));
            }

            IPropertyAdapter propertyAdapter = PropertyAdapter.CreateAdapter(containingType, memberName);

            if (propertyAdapter != null)
            {
                return(ElementPropertyMemberInitializer.Create(propertyAdapter, values, namespaces));
            }

            throw new Granular.Exception("Type \"{0}\" does not contain a member named \"{1}\"", containingType.Name, memberName);
        }
Exemplo n.º 25
0
        public static IElementInitializer Create(IPropertyAdapter propertyAdapter, IEnumerable <object> values, XamlNamespaces namespaces, Uri sourceUri)
        {
            if (!values.Any())
            {
                return(ElementInitializer.Empty);
            }

            if (values.Count() == 1)
            {
                object value = values.First();

                if (propertyAdapter.PropertyType == typeof(IFrameworkElementFactory))
                {
                    return(new FrameworkElementFactoryInitializer(propertyAdapter, ElementFactory.FromValue(value, null, namespaces, sourceUri)));
                }

                Type valueType = value is XamlElement ? ((XamlElement)value).GetElementType() : value.GetType();

                ITypeConverter typeConverter;
                if (propertyAdapter.PropertyType.IsAssignableFrom(valueType) || typeof(IMarkupExtension).IsAssignableFrom(valueType) || TypeConverter.TryGetTypeConverter(valueType, propertyAdapter.PropertyType, out typeConverter))
                {
                    IElementFactory contentFactory = ElementFactory.FromValue(value, propertyAdapter.PropertyType, namespaces, sourceUri);
                    return(new ElementPropertyMemberInitializer(propertyAdapter, contentFactory));
                }
            }

            if (ElementCollectionContentInitailizer.IsCollectionType(propertyAdapter.PropertyType))
            {
                IElementInitializer propertyContentInitializer = ElementCollectionContentInitailizer.Create(values, propertyAdapter.PropertyType);

                // wrap with a factory that creates the collection (when it's null) before adding its values
                return(new ElementPropertyMemberFactoryInitializer(propertyAdapter, propertyContentInitializer));
            }

            if (values.Count() == 1)
            {
                object value = values.First();
                throw new Granular.Exception("Cannot assign value of type \"{0}\" to member of type \"{1}\"", value is XamlElement ? ((XamlElement)value).GetElementType() : value.GetType(), propertyAdapter.PropertyType.Name);
            }

            throw new Granular.Exception("Member of type \"{0}\" cannot have more than one child", propertyAdapter.PropertyType.Name);
        }
Exemplo n.º 26
0
 public ScalarPropertyDataEditor(IPropertyAdapter <TData, TValue> propertyAdapter, TComponent component)
     : base(propertyAdapter, component, ValidationStateAdapter.GetPropertyError)
 {
     _component = component;
 }
Exemplo n.º 27
0
 public FrameworkElementFactoryInitializer(IPropertyAdapter propertyAdapter, IElementFactory elementFactory)
 {
     this.propertyAdapter = propertyAdapter;
     this.elementFactory  = elementFactory;
 }
Exemplo n.º 28
0
        static EditableClassMetadata()
        {
            TextProperty = new ClassTypeGenericPropertyAdapter <EditableClass, string>(_ => _.Text, (t, v) => t.Text = v);

            ReadonlyTextProperty = new ClassTypeGenericPropertyAdapter <EditableClass, string>(_ => _.Text);
        }
Exemplo n.º 29
0
 public void Stub(IPropertyAdapter property)
 {
 }
Exemplo n.º 30
0
            public KeyValueElementFactory(Type keyType, IElementFactory valueFactory, XamlElement xamlElement)
            {
                this.valueFactory = valueFactory;

                keyProperty = GetKeyProperty(valueFactory.ElementType);
                keyDirectiveFactory = GetKeyDirectiveFactory(xamlElement, keyType);

                if (keyDirectiveFactory == null && keyProperty == null)
                {
                    throw new Granular.Exception("Dictionary item \"{0}\" must have a key", xamlElement.Name);
                }
            }
Exemplo n.º 31
0
 public static IElementInitializer FromXamlAttribute(IPropertyAdapter propertyAdapter, XamlAttribute memberAttribute)
 {
     IElementFactory contentFactory = ElementFactory.FromXamlAttribute(memberAttribute, propertyAdapter.PropertyType);
     return new ElementPropertyMemberInitializer(propertyAdapter, contentFactory);
 }
Exemplo n.º 32
0
        public static IElementInitializer FromXamlElement(IPropertyAdapter propertyAdapter, XamlElement memberElement)
        {
            IEnumerable<XamlElement> children = memberElement.GetContentChildren();

            if (!children.Any())
            {
                if (!memberElement.TextValue.IsNullOrEmpty())
                {
                    object value = TypeConverter.ConvertValue(memberElement.TextValue, propertyAdapter.PropertyType, memberElement.Namespaces);
                    return new ElementPropertyMemberInitializer(propertyAdapter, new ConstantElementFactory(value));
                }

                return ElementInitializer.Empty;
            }

            if (ElementCollectionContentInitailizer.IsCollectionType(propertyAdapter.PropertyType) &&
                !(children.Count() == 1 && propertyAdapter.PropertyType.IsAssignableFrom(children.First().GetElementType())))
            {
                IElementInitializer propertyContentInitializer = ElementCollectionContentInitailizer.FromXamlElement(memberElement, propertyAdapter.PropertyType);
                // use a factory that creates the property value before initializing its content (when its null)
                return new ElementPropertyMemberFactoryInitializer(propertyAdapter, propertyContentInitializer);
            }

            if (children.Count() == 1)
            {
                if (propertyAdapter.PropertyType == typeof(IFrameworkElementFactory))
                {
                    return new FrameworkElementFactoryInitializer(propertyAdapter, ElementFactory.FromXamlElement(children.First(), children.First().GetElementType()));
                }

                IElementFactory contentFactory = ElementFactory.FromXamlElement(children.First(), propertyAdapter.PropertyType);
                return new ElementPropertyMemberInitializer(propertyAdapter, contentFactory);
            }

            throw new Granular.Exception("Element \"{0}\" cannot have more than one child", memberElement.Name);
        }
Exemplo n.º 33
0
 private ElementPropertyMemberInitializer(IPropertyAdapter propertyAdapter, IElementFactory propertyValueFactory)
 {
     this.propertyAdapter = propertyAdapter;
     this.propertyValueFactory = propertyValueFactory;
 }
Exemplo n.º 34
0
 public UnitAdapter(IPropertyAdapter propertyAdapter)
 {
     this.propertyAdapter = propertyAdapter;
 }
Exemplo n.º 35
0
 static SampleUserMetadata()
 {
     NameProperty = new ClassTypeGenericPropertyAdapter <SampleUser, string>(_ => _.Name, (t, v) => t.Name = v);
 }
Exemplo n.º 36
0
        public void Stub(IPropertyAdapter property)
        {
            var stub = MockRepository.GenerateStub(property.PropertyType);

            property.Stub(stub);
        }
Exemplo n.º 37
0
            public KeyElementFactory(IElementFactory elementFactory, XamlElement xamlElement)
            {
                this.elementFactory = elementFactory;

                keyDirectiveValue = GetKeyDirectiveValue(xamlElement);
                keyProperty = GetKeyProperty(elementFactory.ElementType);

                if (keyDirectiveValue == null && keyProperty == null)
                {
                    throw new Granular.Exception("Dictionary item \"{0}\" must have a key", xamlElement.Name);
                }
            }
Exemplo n.º 38
0
 public ApplicationController(IPropertyAdapter propertyAdapter)
 {
     this.propertyAdapter = propertyAdapter;
 }
Exemplo n.º 39
0
 public ApplicationController(IPropertyAdapter propertyAdapter)
 {
     this.propertyAdapter = propertyAdapter;
 }
Exemplo n.º 40
0
 public ElementPropertyMemberFactoryInitializer(IPropertyAdapter propertyAdapter, IElementInitializer propertyContentInitializer)
 {
     this.propertyAdapter = propertyAdapter;
     this.propertyValueInitializer = propertyContentInitializer;
 }
Exemplo n.º 41
0
 public void Stub(IPropertyAdapter property)
 {
 }
 static ContainerStructMetadata()
 {
     ItemsProperty = new ValueTypeGenericPropertyAdapter <ContainerStruct, IList <EditableStruct> >(_ => _.Items);
 }
Exemplo n.º 43
0
        public ElementInitializer(XamlElement element)
        {
            elementType = element.GetElementType();
            namespaces = element.Namespaces;

            memberInitializers = CreateMemberInitializers(element);
            contentInitializer = CreateContentInitializer(element);

            nameDirectiveValue = GetNameDirectiveValue(element);
            nameProperty = GetNameProperty(element.GetElementType());
        }
 private static void StubProperty(IPropertyAdapter property)
 {
     Rules
     .First(x => x.CanStub(property.PropertyType))
     .Stub(property);
 }
Exemplo n.º 45
0
        public static IElementInitializer Create(IPropertyAdapter propertyAdapter, IEnumerable<object> values, XamlNamespaces namespaces)
        {
            if (!values.Any())
            {
                return ElementInitializer.Empty;
            }

            if (ElementCollectionContentInitailizer.IsCollectionType(propertyAdapter.PropertyType) &&
                !(values.Count() == 1 && values.First() is XamlElement && propertyAdapter.PropertyType.IsAssignableFrom(((XamlElement)values.First()).GetElementType())))
            {
                IElementInitializer propertyContentInitializer = ElementCollectionContentInitailizer.Create(values, propertyAdapter.PropertyType);

                // wrap with a factory that creates the collection (when it's null) before adding its values
                return new ElementPropertyMemberFactoryInitializer(propertyAdapter, propertyContentInitializer);
            }

            if (values.Count() == 1)
            {
                if (propertyAdapter.PropertyType == typeof(IFrameworkElementFactory))
                {
                    return new FrameworkElementFactoryInitializer(propertyAdapter, ElementFactory.FromValue(values.First(), null, namespaces));
                }

                IElementFactory contentFactory = ElementFactory.FromValue(values.First(), propertyAdapter.PropertyType, namespaces);
                return new ElementPropertyMemberInitializer(propertyAdapter, contentFactory);
            }

            throw new Granular.Exception("Member of type \"{0}\" cannot have more than one child", propertyAdapter.PropertyType.Name);
        }
Exemplo n.º 46
0
 public ElementPropertyMemberFactoryInitializer(IPropertyAdapter propertyAdapter, IElementInitializer propertyContentInitializer)
 {
     this.propertyAdapter          = propertyAdapter;
     this.propertyValueInitializer = propertyContentInitializer;
 }
Exemplo n.º 47
0
 public FrameworkElementFactoryInitializer(IPropertyAdapter propertyAdapter, IElementFactory elementFactory)
 {
     this.propertyAdapter = propertyAdapter;
     this.elementFactory = elementFactory;
 }
Exemplo n.º 48
0
 private ElementPropertyMemberInitializer(IPropertyAdapter propertyAdapter, IElementFactory propertyValueFactory)
 {
     this.propertyAdapter      = propertyAdapter;
     this.propertyValueFactory = propertyValueFactory;
 }
Exemplo n.º 49
0
 public UnitAdapter(IPropertyAdapter propertyAdapter)
 {
     this.propertyAdapter = propertyAdapter;
 }
 public void Stub(IPropertyAdapter property)
 {
     var stub = MockRepository.GenerateStub(property.PropertyType);
     property.Stub(stub);
 }