Exemplo n.º 1
0
        // lookups

        protected virtual XamlMember LookupAliasedProperty(XamlDirective directive)
        {
            XamlMember member = null;

            if (ReferenceEquals(directive, XamlLanguage.Key))
            {
                var a = this.GetCustomAttribute <DictionaryKeyPropertyAttribute>();
                member = a != null?GetMember(a.Name) : null;
            }
            else if (ReferenceEquals(directive, XamlLanguage.Name))
            {
                var a = this.GetCustomAttribute <RuntimeNamePropertyAttribute>();
                member = a != null?GetMember(a.Name) : null;
            }
            else if (ReferenceEquals(directive, XamlLanguage.Uid))
            {
                var a = this.GetCustomAttribute <UidPropertyAttribute>();
                member = a != null?GetMember(a.Name) : null;
            }
            else if (ReferenceEquals(directive, XamlLanguage.Lang))
            {
                var a = this.GetCustomAttribute <XmlLangPropertyAttribute>();
                member = a != null?GetMember(a.Name) : null;
            }
            return(member);
        }
Exemplo n.º 2
0
        public virtual XamlDirective GetXamlDirective(string xamlNamespace, string name)
        {
            XamlDirective t;
            var           p = new Pair(xamlNamespace, name);

            if (!xaml_directives.TryGetValue(p, out t))
            {
                t = new XamlDirective(xamlNamespace, name);
                xaml_directives.Add(p, t);
            }
            return(t);
        }
Exemplo n.º 3
0
        public XamlMember GetAliasedProperty(XamlDirective directive)
        {
            XamlMember member;

            if (aliased_property_cache == null)
            {
                aliased_property_cache = new Dictionary <XamlDirective, XamlMember>(ReferenceComparer.Instance);
            }
            else if (aliased_property_cache.TryGetValue(directive, out member))
            {
                return(member);
            }
            member = LookupAliasedProperty(directive);
            aliased_property_cache[directive] = member;
            return(member);
        }
Exemplo n.º 4
0
        // lookups

        protected virtual XamlMember LookupAliasedProperty(XamlDirective directive)
        {
            XamlMember member = null;

            if (aliased_property_cache == null)
            {
                aliased_property_cache = new Dictionary <XamlDirective, XamlMember> ();
            }
            else if (aliased_property_cache.TryGetValue(directive, out member))
            {
                return(member);
            }

            if (directive == XamlLanguage.Key)
            {
                var a = this.GetCustomAttribute <DictionaryKeyPropertyAttribute> ();
                member = a != null?GetMember(a.Name) : null;
            }
            else if (directive == XamlLanguage.Name)
            {
                var a = this.GetCustomAttribute <RuntimeNamePropertyAttribute> ();
                member = a != null?GetMember(a.Name) : null;
            }
            else if (directive == XamlLanguage.Uid)
            {
                var a = this.GetCustomAttribute <UidPropertyAttribute> ();
                member = a != null?GetMember(a.Name) : null;
            }
            else if (directive == XamlLanguage.Lang)
            {
                var a = this.GetCustomAttribute <XmlLangPropertyAttribute> ();
                member = a != null?GetMember(a.Name) : null;
            }
            aliased_property_cache[directive] = member;
            return(member);
        }
Exemplo n.º 5
0
        static XamlLanguage()
        {
            InitializingTypes = true;

            // types

            Array     = XT <ArrayExtension> ();
            Boolean   = XT <bool> ();
            Byte      = XT <byte> ();
            Char      = XT <char> ();
            Decimal   = XT <decimal> ();
            Double    = XT <double> ();
            Int16     = XT <short> ();
            Int32     = XT <int> ();
            Int64     = XT <long> ();
            Member    = XT <MemberDefinition> ();
            Null      = XT <NullExtension> ();
            Object    = XT <object> ();
            Property  = XT <PropertyDefinition> ();
            Reference = XT <Reference> ();
            Single    = XT <float> ();
            Static    = XT <StaticExtension> ();
            String    = XT <string> ();
            TimeSpan  = XT <TimeSpan> ();
            Type      = XT <TypeExtension> ();
            Uri       = XT <Uri> ();
            XData     = XT <XData> ();

            InitializingTypes = false;

            AllTypes = new ReadOnlyCollection <XamlType> (new XamlType [] { Array, Boolean, Byte, Char, Decimal, Double, Int16, Int32, Int64, Member, Null, Object, Property, Reference, Single, Static, String, TimeSpan, Type, Uri, XData });

            // directives

            // Looks like predefined XamlDirectives have no ValueSerializer.
            // To handle this situation, differentiate them from non-primitive XamlMembers.
            InitializingDirectives = true;

            var nss    = new string [] { XamlLanguage.Xaml2006Namespace };
            var nssXml = new string [] { XamlLanguage.Xml1998Namespace };

            Arguments            = new XamlDirective(nss, "Arguments", XT <List <object> > (), null, AllowedMemberLocations.Any);
            AsyncRecords         = new XamlDirective(nss, "AsyncRecords", XT <string> (), null, AllowedMemberLocations.Attribute);
            Base                 = new XamlDirective(nssXml, "base", XT <string> (), null, AllowedMemberLocations.Attribute);
            Class                = new XamlDirective(nss, "Class", XT <string> (), null, AllowedMemberLocations.Attribute);
            ClassAttributes      = new XamlDirective(nss, "ClassAttributes", XT <List <Attribute> > (), null, AllowedMemberLocations.MemberElement);
            ClassModifier        = new XamlDirective(nss, "ClassModifier", XT <string> (), null, AllowedMemberLocations.Attribute);
            Code                 = new XamlDirective(nss, "Code", XT <string> (), null, AllowedMemberLocations.Attribute);
            ConnectionId         = new XamlDirective(nss, "ConnectionId", XT <string> (), null, AllowedMemberLocations.Any);
            FactoryMethod        = new XamlDirective(nss, "FactoryMethod", XT <string> (), null, AllowedMemberLocations.Any);
            FieldModifier        = new XamlDirective(nss, "FieldModifier", XT <string> (), null, AllowedMemberLocations.Attribute);
            Initialization       = new XamlDirective(nss, "_Initialization", XT <object> (), null, AllowedMemberLocations.Any);
            Items                = new XamlDirective(nss, "_Items", XT <List <object> > (), null, AllowedMemberLocations.Any);
            Key                  = new XamlDirective(nss, "Key", XT <object> (), null, AllowedMemberLocations.Any);
            Lang                 = new XamlDirective(nssXml, "lang", XT <string> (), null, AllowedMemberLocations.Attribute);
            Members              = new XamlDirective(nss, "Members", XT <List <MemberDefinition> > (), null, AllowedMemberLocations.MemberElement);
            Name                 = new XamlDirective(nss, "Name", XT <string> (), null, AllowedMemberLocations.Attribute);
            PositionalParameters = new XamlDirective(nss, "_PositionalParameters", XT <List <object> > (), null, AllowedMemberLocations.Any);
            Space                = new XamlDirective(nssXml, "space", XT <string> (), null, AllowedMemberLocations.Attribute);
            Subclass             = new XamlDirective(nss, "Subclass", XT <string> (), null, AllowedMemberLocations.Attribute);
            SynchronousMode      = new XamlDirective(nss, "SynchronousMode", XT <string> (), null, AllowedMemberLocations.Attribute);
            Shared               = new XamlDirective(nss, "Shared", XT <string> (), null, AllowedMemberLocations.Attribute);
            TypeArguments        = new XamlDirective(nss, "TypeArguments", XT <string> (), null, AllowedMemberLocations.Attribute);
            Uid                  = new XamlDirective(nss, "Uid", XT <string> (), null, AllowedMemberLocations.Attribute);
            UnknownContent       = new XamlDirective(nss, "_UnknownContent", XT <object> (), null, AllowedMemberLocations.MemberElement)
            {
                InternalIsUnknown = true
            };

            AllDirectives = new ReadOnlyCollection <XamlDirective> (new XamlDirective [] { Arguments, AsyncRecords, Base, Class, ClassAttributes, ClassModifier, Code, ConnectionId, FactoryMethod, FieldModifier, Initialization, Items, Key, Lang, Members, Name, PositionalParameters, Space, Subclass, SynchronousMode, Shared, TypeArguments, Uid, UnknownContent });

            InitializingDirectives = false;

            SpecialNames = new SpecialTypeNameList();
        }
Exemplo n.º 6
0
 public DirectiveMemberInvoker(XamlDirective directive)
     : base(directive)
 {
 }
Exemplo n.º 7
0
        // returns remaining attributes to be processed
        Dictionary <string, string> ProcessAttributes(XmlReader r, List <Pair> members)
        {
            var l = members;

            // base (top element)
            if (!xmlbase_done)
            {
                xmlbase_done = true;
                string xmlbase = r.GetAttribute("base", XamlLanguage.Xml1998Namespace) ?? r.BaseURI;
                if (xmlbase != null)
                {
                    l.Add(new Pair(XamlLanguage.Base, xmlbase));
                }
            }

            var atts = new Dictionary <string, string> ();

            if (r.MoveToFirstAttribute())
            {
                do
                {
                    switch (r.NamespaceURI)
                    {
                    case XamlLanguage.Xml1998Namespace:
                        switch (r.LocalName)
                        {
                        case "base":
                            continue;                             // already processed.

                        case "lang":
                            l.Add(new Pair(XamlLanguage.Lang, r.Value));
                            continue;

                        case "space":
                            l.Add(new Pair(XamlLanguage.Space, r.Value));
                            continue;
                        }
                        break;

                    case XamlLanguage.Xmlns2000Namespace:
                        continue;

                    case XamlLanguage.Xaml2006Namespace:
                        XamlDirective d = FindStandardDirective(r.LocalName, AllowedMemberLocations.Attribute);
                        if (d != null)
                        {
                            l.Add(new Pair(d, r.Value));
                            continue;
                        }
                        throw new NotSupportedException(String.Format("Attribute '{0}' is not supported", r.Name));

                    default:
                        if (r.NamespaceURI == String.Empty)
                        {
                            atts.Add(r.Name, r.Value);
                            continue;
                        }
                        // Should we just ignore unknown attribute in XAML namespace or any other namespaces ?
                        // Probably yes for compatibility with future version.
                        break;
                    }
                } while (r.MoveToNextAttribute());
                r.MoveToElement();
            }
            return(atts);
        }
Exemplo n.º 8
0
        // returns remaining attributes to be processed
        List <StringPair> ProcessAttributes(XmlReader r, List <Pair> members, out string typeArgNames)
        {
            // base (top element)
            if (!xmlbase_done)
            {
                xmlbase_done = true;
                string xmlbase = r.GetAttribute("base", XamlLanguage.Xml1998Namespace) ?? r.BaseURI;
                if (xmlbase != null)
                {
                    members.Add(new Pair(XamlLanguage.Base, xmlbase));
                }
            }
            typeArgNames = null;
            var atts         = new List <StringPair>();
            var tagNamespace = r.NamespaceURI;

            if (r.MoveToFirstAttribute())
            {
                do
                {
                    switch (r.NamespaceURI)
                    {
                    case XamlLanguage.Xml1998Namespace:
                        switch (r.LocalName)
                        {
                        case "base":
                            continue;                                             // already processed.

                        case "lang":
                            members.Add(new Pair(XamlLanguage.Lang, r.Value));
                            continue;

                        case "space":
                            members.Add(new Pair(XamlLanguage.Space, r.Value));
                            continue;
                        }
                        break;

                    case XamlLanguage.Xmlns2000Namespace:
                        continue;

                    case XamlLanguage.Xaml2006Namespace:
                        XamlDirective d = FindStandardDirective(r.LocalName, AllowedMemberLocations.Attribute);
                        if (d != null)
                        {
                            // check TypeArguments to resolve Type, and remove them from the list. They don't appear as a node.
                            if (ReferenceEquals(d, XamlLanguage.TypeArguments))
                            {
                                typeArgNames = r.Value;
                                continue;
                            }
                            members.Add(new Pair(d, r.Value));
                            continue;
                        }
                        throw new NotSupportedException(String.Format("Attribute '{0}' is not supported", r.Name));

                    default:
                        if (string.IsNullOrEmpty(r.NamespaceURI) || tagNamespace == r.NamespaceURI || r.LocalName.IndexOf('.') > 0)
                        {
                            atts.Add(new StringPair(r.Name, r.Value));
                            continue;
                        }
                        // Custom directive
                        members.Add(new Pair(SchemaContext.GetXamlDirective(r.NamespaceURI, r.LocalName), r.Value));
                        break;
                    }
                } while (r.MoveToNextAttribute());
                r.MoveToElement();
            }
            return(atts);
        }
Exemplo n.º 9
0
			public DirectiveMemberInvoker (XamlDirective directive)
				: base (directive)
			{
			}
Exemplo n.º 10
0
 public XamlMember GetAliasedProperty(XamlDirective directive)
 {
     return(LookupAliasedProperty(directive));
 }