예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 private static IPropertyAdapter GetKeyProperty(Type type)
 {
     return(PropertyAdapter.CreateAdapter(type, new XamlName(PropertyAttribute.GetPropertyName <DictionaryKeyPropertyAttribute>(type))));
 }
예제 #5
0
 private static IPropertyAdapter GetNameProperty(Type type)
 {
     return(PropertyAdapter.CreateAdapter(type, new XamlName(PropertyAttribute.GetPropertyName <RuntimeNamePropertyAttribute>(type))));
 }