public void CtorTest () { ContentPropertyAttribute attr = new ContentPropertyAttribute ("name"); Assert.AreEqual ("name", attr.Name); attr = new ContentPropertyAttribute (); Assert.IsNull (attr.Name); }
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)); }
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); }