Exemplo n.º 1
0
		public void CtorTest ()
		{
			ContentPropertyAttribute attr = new ContentPropertyAttribute ("name");
			Assert.AreEqual ("name", attr.Name);

			attr = new ContentPropertyAttribute ();
			Assert.IsNull (attr.Name);
		}
Exemplo n.º 2
0
        public static IElementFactory FromXamlElement(XamlElement element, Type targetType)
        {
            Type elementType = element.GetElementType();

            if (element.Values.Any() && ContentPropertyAttribute.GetPropertyName(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));
        }
Exemplo n.º 3
0
        private static IElementInitializer CreateContentInitializer(XamlElement element, Type elementType)
        {
            if (!element.Values.Any())
            {
                return(null);
            }

            string contentPropertyName = ContentPropertyAttribute.GetPropertyName(elementType);

            if (!contentPropertyName.IsNullOrEmpty())
            {
                return(ElementMemberInitializer.Create(elementType, contentPropertyName, 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);
        }