Example #1
0
 public virtual XamlDirective GetXamlDirective(string xamlNamespace, string name)
 {
     lock (gate)
     {
         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);
     }
 }
Example #2
0
        // lookups

        protected virtual XamlMember LookupAliasedProperty(XamlDirective directive)
        {
            if (directive == XamlLanguage.Key)
            {
                var a = this.GetCustomAttribute <DictionaryKeyPropertyAttribute> ();
                return(a != null?GetMember(a.Name) : null);
            }
            if (directive == XamlLanguage.Name)
            {
                var a = this.GetCustomAttribute <RuntimeNamePropertyAttribute> ();
                return(a != null?GetMember(a.Name) : null);
            }
            if (directive == XamlLanguage.Uid)
            {
                var a = this.GetCustomAttribute <UidPropertyAttribute> ();
                return(a != null?GetMember(a.Name) : null);
            }
            if (directive == XamlLanguage.Lang)
            {
                var a = this.GetCustomAttribute <XmlLangPropertyAttribute> ();
                return(a != null?GetMember(a.Name) : null);
            }
            return(null);
        }
Example #3
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;

                // if (!string.IsNullOrEmpty(r.BaseURI))
                {
                    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;
                        }
                        else
                        {
                            l.Add(new Pair(new XamlDirective(r.NamespaceURI, r.LocalName), r.Value));
                            continue;
                        }

                    case XamlLanguage.XmlnsMCNamespace:
                        l.Add(new Pair(XamlLanguage.Ignorable, r.Value));
                        break;

                    default:
                        if (IsIgnored(r.Prefix))
                        {
                            continue;
                        }

                        if (r.NamespaceURI == String.Empty || r.NamespaceURI == r.LookupNamespace(""))
                        {
                            atts.Add(r.LocalName, r.Value);
                            continue;
                        }
                        if (r.NamespaceURI.StartsWith("using:"))
                        {
                            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);
        }
Example #4
0
 public XamlMember GetAliasedProperty(XamlDirective directive)
 {
     return(LookupAliasedProperty(directive));
 }
Example #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>();
            Bind      = XT <Bind>();
            XData     = XT <XData> ();

            InitializingTypes = false;

            AllTypes = new ReadOnlyCollection <XamlType> (new XamlType [] { Array, Boolean, Byte, Char, Decimal, Double, Int16, Int32, Int64, Member, Null, Object, Bind, 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
            };
            Ignorable = new XamlDirective(nss, "Ignorable", 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();
        }
Example #6
0
 public DirectiveMemberInvoker(XamlDirective directive)
     : base(directive)
 {
 }