public static IElementFactory FromXamlElement(XamlElement element, Type targetType) { Type elementType = element.GetElementType(); if (element.Values.Any() && PropertyAttribute.GetPropertyName <ContentPropertyAttribute>(elementType).IsNullOrEmpty() && !ElementCollectionContentInitailizer.IsCollectionType(elementType)) { return(FromElementFactory(FromXamlElementContent(element), targetType, element.Namespaces, element.SourceUri)); } IElementInitializer elementInitializer = new ElementInitializer(element); IElementFactory elementFactory = new ElementFactory(elementType, elementInitializer); return(FromElementFactory(elementFactory, targetType, element.Namespaces, element.SourceUri)); }
private static IElementInitializer CreateContentInitializer(XamlElement element) { Type elementType = element.GetElementType(); string contentPropertyName = PropertyAttribute.GetPropertyName <ContentPropertyAttribute>(elementType); if (!contentPropertyName.IsNullOrEmpty()) { return(ElementMemberInitializer.Create(new XamlName(contentPropertyName), elementType, element.Values, element.Namespaces)); } if (ElementCollectionContentInitailizer.IsCollectionType(elementType)) { return(ElementCollectionContentInitailizer.Create(element.Values, elementType)); } return(null); }
private static IElementInitializer CreateContentInitializer(XamlElement element, Type elementType) { if (!element.Values.Any()) { return(null); } string contentPropertyName = PropertyAttribute.GetPropertyName <ContentPropertyAttribute>(elementType); if (!contentPropertyName.IsNullOrEmpty()) { return(ElementMemberInitializer.Create(new XamlName(contentPropertyName), elementType, element.Values, element.Namespaces, element.SourceUri)); } if (ElementCollectionContentInitailizer.IsCollectionType(elementType)) { return(ElementCollectionContentInitailizer.Create(element.Values, elementType)); } throw new Granular.Exception("Cannot add content to element of type \"{0}\" as it's not a collection type and does not declare ContentProperty", elementType.Name); }
private static IPropertyAdapter GetKeyProperty(Type type) { return(PropertyAdapter.CreateAdapter(type, new XamlName(PropertyAttribute.GetPropertyName <DictionaryKeyPropertyAttribute>(type)))); }
private static IPropertyAdapter GetNameProperty(Type type) { return(PropertyAdapter.CreateAdapter(type, new XamlName(PropertyAttribute.GetPropertyName <RuntimeNamePropertyAttribute>(type)))); }