Example #1
0
        private static XamlMember CreateXamlMember(XAttribute attribute, XamlNamespaces namespaces)
        {
            XamlName name  = new XamlName(attribute.Name.LocalName, attribute.Name.NamespaceName.IsNullOrEmpty() ? namespaces.Get(String.Empty) : attribute.Name.NamespaceName);
            object   value = (object)MarkupExtensionParser.Parse(attribute.Value, namespaces);

            return(new XamlMember(name, namespaces, value));
        }
Example #2
0
        private static XamlMember CreateXamlMember(XAttribute attribute, XamlNamespaces namespaces)
        {
            XamlName name = new XamlName(attribute.Name.LocalName, attribute.Name.NamespaceName.IsNullOrEmpty() ? namespaces.Get(String.Empty) : attribute.Name.NamespaceName);
            object value = (object)MarkupExtensionParser.Parse(attribute.Value, namespaces);

            return new XamlMember(name, namespaces, value);
        }
Example #3
0
 public XamlElement(XamlName name, XamlNamespaces namespaces, IEnumerable <XamlMember> members = null, IEnumerable <object> values = null, IEnumerable <XamlMember> directives = null) :
     base(name, namespaces)
 {
     this.Members    = members ?? EmptyMembers;
     this.Values     = values ?? EmptyValues;
     this.Directives = directives ?? EmptyDirectives;
 }
Example #4
0
 public XamlElement(XamlName name, XamlNamespaces namespaces, IEnumerable<XamlAttribute> attributes = null, IEnumerable<XamlElement> children = null, string textValue = null)
     : base(name, namespaces)
 {
     this.Attributes = attributes ?? new XamlAttribute[0];
     this.Children = children ?? new XamlElement[0];
     this.TextValue = textValue ?? String.Empty;
 }
Example #5
0
 public XamlElement(XamlName name, XamlNamespaces namespaces, IEnumerable<XamlMember> members = null, IEnumerable<object> values = null, IEnumerable<XamlMember> directives = null)
     : base(name, namespaces)
 {
     this.Members = members ?? EmptyMembers;
     this.Values = values ?? EmptyValues;
     this.Directives = directives ?? EmptyDirectives;
 }
Example #6
0
        public override bool Equals(object obj)
        {
            XamlName other = obj as XamlName;

            return(Object.ReferenceEquals(this, other) || !Object.ReferenceEquals(other, null) &&
                   this.LocalName == other.LocalName &&
                   this.NamespaceName == other.NamespaceName);
        }
Example #7
0
        public static RoutedEvent GetRoutedEvent(XamlName eventName)
        {
            if (!eventName.IsMemberName)
            {
                throw new Granular.Exception("Invalid routed event name \"{0}\"", eventName.LocalName);
            }

            Type ownerType = TypeParser.ParseType(eventName.ContainingTypeName);
            return GetOwnedRoutedEvent(ownerType, eventName.MemberName);
        }
Example #8
0
        public static bool TryResolveType(XamlName name, out Type type)
        {
            if (XamlTypes.TryParseXamlType(name, out type))
            {
                return true;
            }

            XamlName extensionName = new XamlName(String.Format("{0}Extension", name.LocalName), name.NamespaceName);

            return TryGetType(name, out type) || TryGetType(extensionName, out type);
        }
Example #9
0
        public static Type ParseType(XamlName name)
        {
            Type type;

            if (!TryParseType(name, out type))
            {
                throw new Granular.Exception("Type \"{0}\" wasn't found", name);
            }

            return type;
        }
Example #10
0
        public static Type ParseXamlType(XamlName xamlName)
        {
            Type type;

            if (!TryParseXamlType(xamlName, out type))
            {
                throw new Granular.Exception("Type {0} wasn't found", xamlName);
            }

            return type;
        }
Example #11
0
        private static XamlMember CreateXamlMember(XElement element, XamlNamespaces namespaces)
        {
            XamlName name = new XamlName(element.Name.LocalName, element.Name.NamespaceName.IsNullOrEmpty() ? namespaces.Get(String.Empty) : element.Name.NamespaceName);

            if (element.Attributes().Any())
            {
                throw new Granular.Exception("Member \"{0}\" cannot contain attributes", element.Name);
            }

            if (element.Elements().Any(child => IsMemberName(child.Name)))
            {
                throw new Granular.Exception("Member \"{0}\" cannot contain member elements", element.Name);
            }

            return(new XamlMember(name, namespaces, CreateValues(element, namespaces)));
        }
Example #12
0
        public static string ParseTypeName(this ITypeParser typeParser, XamlName name)
        {
            if (XamlLanguage.IsXamlType(name))
            {
                return String.Empty;
            }

            string typeName;

            if (!typeParser.TryParseTypeName(name.LocalName, name.NamespaceName, out typeName))
            {
                throw new Granular.Exception("Type \"{0}\" wasn't found", name);
            }

            return typeName;
        }
Example #13
0
        private static XamlMember CreateXamlMember(XElement element, XamlNamespaces namespaces)
        {
            XamlName name = new XamlName(element.Name.LocalName, element.Name.NamespaceName.IsNullOrEmpty() ? namespaces.Get(String.Empty) : element.Name.NamespaceName);

            if (element.Attributes().Any())
            {
                throw new Granular.Exception("Member \"{0}\" cannot contain attributes", element.Name);
            }

            if (element.Elements().Any(child => IsMemberName(child.Name)))
            {
                throw new Granular.Exception("Member \"{0}\" cannot contain member elements", element.Name);
            }

            return new XamlMember(name, namespaces, CreateValues(element, namespaces));
        }
Example #14
0
        public XamlName(string localName, string namespaceName = null)
        {
            this.LocalName = localName ?? String.Empty;
            this.NamespaceName = namespaceName ?? String.Empty;

            int typeSeparatorIndex = LocalName.IndexOf('.');

            if (typeSeparatorIndex != -1)
            {
                MemberName = LocalName.Substring(typeSeparatorIndex + 1);
                ContainingTypeName = new XamlName(LocalName.Substring(0, typeSeparatorIndex), NamespaceName);

                IsMemberName = true;
            }
            else
            {
                MemberName = LocalName;
            }
        }
Example #15
0
        public XamlName(string localName, string namespaceName = null)
        {
            this.LocalName     = localName ?? String.Empty;
            this.NamespaceName = namespaceName ?? String.Empty;

            int typeSeparatorIndex = LocalName.IndexOf('.');

            if (typeSeparatorIndex != -1)
            {
                MemberName         = LocalName.Substring(typeSeparatorIndex + 1);
                ContainingTypeName = new XamlName(LocalName.Substring(0, typeSeparatorIndex), NamespaceName);

                IsMemberName = true;
            }
            else
            {
                MemberName = LocalName;
            }
        }
Example #16
0
        public static IEventAdapter CreateAdapter(Type targetType, XamlName eventName)
        {
            RoutedEvent routedEvent = GetRoutedEvent(targetType, eventName);
            if (routedEvent != null)
            {
                return new RoutedEventAdapter(routedEvent);
            }

            EventInfo clrEvent = GetClrEvent(targetType, eventName);
            if (clrEvent != null)
            {
                return new ClrEventAdapter(clrEvent);
            }

            PropertyInfo eventProperty = GetEventProperty(targetType, eventName);
            if (eventProperty != null)
            {
                return new EventPropertyAdapter(eventProperty);
            }

            return null;
        }
Example #17
0
        public static bool TryGetValue(object target, XamlName propertyName, out object value)
        {
            DependencyProperty dependencyProperty = DependencyProperty.GetProperty(target.GetType(), propertyName);
            if (dependencyProperty != null && target is DependencyObject)
            {
                value = ((DependencyObject)target).GetValue(dependencyProperty);
                return true;
            }

            Type propertyContainingType = propertyName.IsMemberName ? TypeParser.ParseType(propertyName.ContainingTypeName) : target.GetType();

            PropertyInfo propertyInfo = propertyContainingType.GetInstanceProperty(propertyName.MemberName);
            if (propertyInfo != null && !propertyInfo.GetIndexParameters().Any())
            {
                value = propertyInfo.GetValue(target, new object[0]);
                return true;
            }

            value = null;
            return false;
        }
Example #18
0
 public PropertyPathElement(XamlName propertyName)
 {
     this.PropertyName = propertyName;
 }
Example #19
0
 public IndexPropertyPathElement(XamlName propertyName, IEnumerable<string> indexRawValues, XamlNamespaces namespaces)
 {
     this.PropertyName = propertyName;
     this.IndexRawValues = indexRawValues;
     this.namespaces = namespaces;
 }
Example #20
0
        private static PropertyInfo GetClrProperty(Type containingType, XamlName propertyName)
        {
            string propertyMemberName = propertyName.MemberName;
            Type propertyContainingType = propertyName.IsMemberName ? TypeParser.ParseType(propertyName.ContainingTypeName) : containingType;

            return propertyContainingType.GetInstanceProperty(propertyMemberName);
        }
Example #21
0
        public static IPropertyAdapter CreateAdapter(Type targetType, XamlName propertyName)
        {
            if (propertyName.IsEmpty)
            {
                return null;
            }

            DependencyProperty dependencyProperty = DependencyProperty.GetProperty(targetType, propertyName);
            if (dependencyProperty != null)
            {
                return new DependencyPropertyAdapter(dependencyProperty);
            }

            PropertyInfo clrProperty = GetClrProperty(targetType, propertyName);
            if (clrProperty != null)
            {
                return new ClrPropertyAdapter(clrProperty);
            }

            return null;
        }
Example #22
0
 public XamlNode(XamlName name, XamlNamespaces namespaces)
 {
     this.Name = name;
     this.Namespaces = namespaces;
 }
Example #23
0
        private static EventInfo GetClrEvent(Type containingType, XamlName eventName)
        {
            string eventMemberName = eventName.MemberName;
            Type eventContainingType = eventName.IsMemberName ? TypeParser.ParseType(eventName.ContainingTypeName) : containingType;

            return eventContainingType.GetEvent(eventMemberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
        }
Example #24
0
 public XamlAttribute(XamlName name, XamlNamespaces namespaces, object value)
     : base(name, namespaces)
 {
     this.Value = value;
 }
Example #25
0
 public XamlMember(XamlName name, XamlNamespaces namespaces, IEnumerable <object> values) :
     base(name, namespaces)
 {
     this.Values = values ?? EmptyValues;
 }
Example #26
0
        public static IElementInitializer FromXamlElement(XamlName memberName, XamlElement memberElement, Type containingType)
        {
            IEventAdapter eventAdapter = EventAdapter.CreateAdapter(containingType, memberName);
            if (eventAdapter != null)
            {
                return ElementEventMemberInitializer.FromXamlElement(eventAdapter, memberElement);
            }

            IPropertyAdapter propertyAdapter = PropertyAdapter.CreateAdapter(containingType, memberName);
            if (propertyAdapter != null)
            {
                return ElementPropertyMemberInitializer.FromXamlElement(propertyAdapter, memberElement);
            }

            throw new Granular.Exception("Type \"{0}\" does not contain a member named \"{1}\"", containingType.Name, memberName);
        }
Example #27
0
 public XamlNode(XamlName name, XamlNamespaces namespaces)
 {
     this.Name       = name;
     this.Namespaces = namespaces;
 }
Example #28
0
        public static IElementInitializer Create(XamlName memberName, Type containingType, IEnumerable<object> values, XamlNamespaces namespaces)
        {
            IEventAdapter eventAdapter = EventAdapter.CreateAdapter(containingType, memberName);
            if (eventAdapter != null)
            {
                return new ElementEventMemberInitializer(eventAdapter, GetEventHandlerName(memberName, values));
            }

            IPropertyAdapter propertyAdapter = PropertyAdapter.CreateAdapter(containingType, memberName);
            if (propertyAdapter != null)
            {
                return ElementPropertyMemberInitializer.Create(propertyAdapter, values, namespaces);
            }

            throw new Granular.Exception("Type \"{0}\" does not contain a member named \"{1}\"", containingType.Name, memberName);
        }
Example #29
0
        private static PropertyInfo GetEventProperty(Type containingType, XamlName eventName)
        {
            string eventMemberName = eventName.MemberName;
            Type eventContainingType = eventName.IsMemberName ? TypeParser.ParseType(eventName.ContainingTypeName) : containingType;

            PropertyInfo eventProperty = eventContainingType.GetInstanceProperty(eventMemberName);
            return eventProperty != null && eventProperty.IsDelegate() ? eventProperty : null;
        }
Example #30
0
        private static RoutedEvent GetRoutedEvent(Type containingType, XamlName eventName)
        {
            string eventMemberName = eventName.MemberName;
            Type eventContainingType = eventName.IsMemberName ? TypeParser.ParseType(eventName.ContainingTypeName) : containingType;

            return EventManager.GetOwnedRoutedEvent(containingType, eventMemberName);
        }
Example #31
0
 public static bool IsDirective(XamlName name)
 {
     return(Directives.Contains(name));
 }
Example #32
0
        public static bool TryGetMemberValue(this XamlElement element, XamlName memberName, out object value)
        {
            XamlAttribute memberAttribute = element.Attributes.Where(attribute => attribute.Name == memberName).FirstOrDefault();
            if (memberAttribute != null)
            {
                value = memberAttribute.Value;
                return true;
            }

            XamlElement memberChild = element.Children.Where(child => child.Name == memberName).FirstOrDefault();
            if (memberChild != null)
            {
                value = memberChild.GetMemberValue();
                return true;
            }

            value = null;
            return false;
        }
Example #33
0
 public static bool TryParseType(XamlName name, out Type type)
 {
     return resolvedTypesCache.TryGetValue(name, out type);
 }
Example #34
0
 public static bool IsXamlType(XamlName name)
 {
     return(XamlTypes.Contains(name));
 }
Example #35
0
        private static bool TryGetType(XamlName xamlName, out Type type)
        {
            if (xamlName.NamespaceName.StartsWith(ClrNamespacePrefix))
            {
                string clrNamespace = GetClrNamespace(xamlName.NamespaceName.Substring(ClrNamespacePrefix.Length));
                string assemblyName = GetAssemblyName(xamlName.NamespaceName.Substring(ClrNamespacePrefix.Length));

                if (TryGetType(xamlName.LocalName, clrNamespace, assemblyName, out type))
                {
                    return true;
                }

                return false;
            }

            foreach (XmlnsDefinitionAttribute xmlnsDefinition in GetXmlnsDefinitionAttributes())
            {
                if (xmlnsDefinition.XmlNamespace == xamlName.NamespaceName &&
                    TryGetType(xamlName.LocalName, xmlnsDefinition.ClrNamespace, xmlnsDefinition.AssemblyName, out type))
                {
                    return true;
                }
            }

            type = null;
            return false;
        }
Example #36
0
 public XamlMember(XamlName name, XamlNamespaces namespaces, object value)
     : this(name, namespaces, new object[] { value })
 {
     //
 }
Example #37
0
        private static string GetEventHandlerName(XamlName memberName, IEnumerable<object> values)
        {
            if (!values.Any())
            {
                throw new Granular.Exception("Member \"{0}\" doesn't have values", memberName);
            }

            if (values.Count() > 1)
            {
                throw new Granular.Exception("Member \"{0}\" cannot have multiple values", memberName);
            }

            if (!(values.First() is String))
            {
                throw new Granular.Exception("Member \"{0}\" value is not an event handler name", memberName);
            }

            return (string)values.First();
        }
Example #38
0
 public XamlMember(XamlName name, XamlNamespaces namespaces, IEnumerable<object> values)
     : base(name, namespaces)
 {
     this.Values = values ?? EmptyValues;
 }
Example #39
0
 public static bool TryParseXamlType(XamlName name, out Type type)
 {
     return TypeProviders.TryGetValue(name, out type);
 }
Example #40
0
 public XamlMember(XamlName name, XamlNamespaces namespaces, object value) :
     this(name, namespaces, new object[] { value })
 {
     //
 }