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); }
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); }
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); }
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); }
/// <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; }
/// <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; }
/// <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; }
static EditableStructMetadata() { TextProperty = new ValueTypeGenericPropertyAdapter <EditableStruct, string>(_ => _.Text, (t, v) => { t.Text = v; return(t); }); ReadonlyTextProperty = new ValueTypeGenericPropertyAdapter <EditableStruct, string>(_ => _.Text); }
public PropertyController( IPropertyAdapter propertyAdapter, ISearchAdapter searchAdapter, IAuthAdapter authAdapter, IListingAdapter listingAdapter) { this.propertyAdapter = propertyAdapter; this.searchAdapter = searchAdapter; this.authAdapter = authAdapter; this.listingAdapter = listingAdapter; }
public ElementInitializer(XamlElement element) { elementType = element.GetElementType(); namespaces = element.Namespaces; memberInitializers = CreateMemberInitializers(element); contentInitializer = CreateContentInitializer(element); nameDirectiveValue = GetNameDirectiveValue(element); nameProperty = GetNameProperty(element.GetElementType()); }
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); } }
/// <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; }
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(); } }
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> >(); }
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; }
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); }
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); }
public ScalarPropertyDataEditor(IPropertyAdapter <TData, TValue> propertyAdapter, TComponent component) : base(propertyAdapter, component, ValidationStateAdapter.GetPropertyError) { _component = component; }
public FrameworkElementFactoryInitializer(IPropertyAdapter propertyAdapter, IElementFactory elementFactory) { this.propertyAdapter = propertyAdapter; this.elementFactory = elementFactory; }
static EditableClassMetadata() { TextProperty = new ClassTypeGenericPropertyAdapter <EditableClass, string>(_ => _.Text, (t, v) => t.Text = v); ReadonlyTextProperty = new ClassTypeGenericPropertyAdapter <EditableClass, string>(_ => _.Text); }
public void Stub(IPropertyAdapter property) { }
public static IElementInitializer FromXamlAttribute(IPropertyAdapter propertyAdapter, XamlAttribute memberAttribute) { IElementFactory contentFactory = ElementFactory.FromXamlAttribute(memberAttribute, propertyAdapter.PropertyType); return new ElementPropertyMemberInitializer(propertyAdapter, contentFactory); }
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); }
private ElementPropertyMemberInitializer(IPropertyAdapter propertyAdapter, IElementFactory propertyValueFactory) { this.propertyAdapter = propertyAdapter; this.propertyValueFactory = propertyValueFactory; }
public UnitAdapter(IPropertyAdapter propertyAdapter) { this.propertyAdapter = propertyAdapter; }
static SampleUserMetadata() { NameProperty = new ClassTypeGenericPropertyAdapter <SampleUser, string>(_ => _.Name, (t, v) => t.Name = v); }
public void Stub(IPropertyAdapter property) { var stub = MockRepository.GenerateStub(property.PropertyType); property.Stub(stub); }
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); } }
public ApplicationController(IPropertyAdapter propertyAdapter) { this.propertyAdapter = propertyAdapter; }
public ElementPropertyMemberFactoryInitializer(IPropertyAdapter propertyAdapter, IElementInitializer propertyContentInitializer) { this.propertyAdapter = propertyAdapter; this.propertyValueInitializer = propertyContentInitializer; }
static ContainerStructMetadata() { ItemsProperty = new ValueTypeGenericPropertyAdapter <ContainerStruct, IList <EditableStruct> >(_ => _.Items); }
private static void StubProperty(IPropertyAdapter property) { Rules .First(x => x.CanStub(property.PropertyType)) .Stub(property); }
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); }