Esempio n. 1
0
        private static IEnumerable <IElementInitializer> CreateMemberInitializers(XamlElement element, Type elementType)
        {
            List <IElementInitializer> list = new List <IElementInitializer>();

            int index = 0;

            foreach (XamlMember member in element.Members)
            {
                // markup extensions may contain members with an empty name, the name should be resolved from the member index
                XamlName memberName = member.Name.IsEmpty ? GetParameterName(elementType, index) : member.Name;

                list.Add(ElementMemberInitializer.Create(memberName.ResolveContainingType(elementType), memberName.MemberName, member.Values, member.Namespaces, member.SourceUri));
                index++;
            }

            return(list);
        }
Esempio n. 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);
        }
Esempio 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);
        }