示例#1
0
        //  ========================== private ================================

        private XamlMember GetXamlAttributeProperty(XamlParserContext context, XamlPropertyName propName,
                                                    XamlType tagType, string tagNamespace, bool tagIsRoot)
        {
            XamlMember prop = null;
            string     ns   = context.GetAttributeNamespace(propName, tagNamespace);

            // No Namespace, == Unknown Property
            if (ns == null)
            {
                XamlMember unknownProperty;
                if (propName.IsDotted)
                {
                    XamlType attachedOwnerType = new XamlType(string.Empty, propName.OwnerName, null, context.SchemaContext);
                    unknownProperty = new XamlMember(propName.Name, attachedOwnerType, true /*isAttachable*/);
                }
                else
                {
                    unknownProperty = new XamlMember(propName.Name, tagType, false);
                }
                return(unknownProperty);
            }

            // Get the property (attached, normal, or directive)
            if (propName.IsDotted)
            {
                prop = context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot);
            }
            else
            {
                prop = context.GetNoDotAttributeProperty(tagType, propName, tagNamespace, ns, tagIsRoot);
            }

            return(prop);
        }
示例#2
0
        private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlTextReaderSettings settings)
        {
            XmlReader myXmlReader;

            if (givenXmlReader == null)
            {
                throw new ArgumentNullException("XmlReader is null");
            }

            _mergedSettings = (settings == null) ? new XamlTextReaderSettings() : new XamlTextReaderSettings(settings);

            //Wrap the xmlreader with a XmlCompatReader instance to apply MarkupCompat rules.
            if (!_mergedSettings.SkipXmlCompatibilityProcessing)
            {
                XmlCompatibilityReader mcReader =
                    new XmlCompatibilityReader(givenXmlReader,
                                               new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported)
                                               );
                myXmlReader = mcReader;
            }
            else
            {   // Don't wrap the xmlreader with XmlCompatReader.
                // Useful for uses where users want to keep mc: content in the XamlNode stream.
                // Or have already processed the markup compat and want that extra perf.
                // We need to go make sure the parser thinks it knows mc: uri,
                // in case SkipXmlCompatibilityProcessing is true... likely won't work yet.
                myXmlReader = givenXmlReader;
            }
            // Pick up the XmlReader settings to override the "settings" defaults.
            if (!String.IsNullOrEmpty(myXmlReader.BaseURI))
            {
                _mergedSettings.BaseUri = new Uri(myXmlReader.BaseURI);
            }
            if (myXmlReader.XmlSpace == XmlSpace.Preserve)
            {
                _mergedSettings.XmlSpacePreserve = true;
            }
            if (!String.IsNullOrEmpty(myXmlReader.XmlLang))
            {
                _mergedSettings.XmlLang = myXmlReader.XmlLang;
            }

            if (schemaContext == null)
            {
                schemaContext = new XamlSchemaContext();
            }

            _endOfStreamNode = new InternalNode(InternalNodeType.EndOfStream);

            _context = (XamlParserContext)XamlContext.CreateContext(UsageMode.Parser, schemaContext,
                                                                    _mergedSettings.LocalAssembly, false /*ignoreCanConvert*/);

            XamlScanner    xamlScanner = new XamlScanner(_context, myXmlReader, _mergedSettings);
            XamlPullParser parser      = new XamlPullParser(_context, xamlScanner, _mergedSettings);

            _nodeStream = new NodeStreamSorter(_context, parser, _mergedSettings);
            _current    = _endOfStreamNode; // user must call Read() before using properties.
        }
 public MeScanner(XamlParserContext context, string text, int lineNumber, int linePosition)
 {
     this._context       = context;
     this._inputText     = text;
     this._lineNumber    = lineNumber;
     this._startPosition = linePosition;
     this._idx           = -1;
     this._state         = StringState.Value;
 }
 public NodeStreamSorter(XamlParserContext context, XamlPullParser parser, XamlXmlReaderSettings settings, Dictionary <string, string> xmlnsDictionary)
 {
     this._context          = context;
     this._settings         = settings;
     this._source           = parser.Parse().GetEnumerator();
     this._xmlnsDictionary  = xmlnsDictionary;
     this._buffer           = new Queue <XamlNode>();
     this._sortingInfoArray = null;
     this.StartNewNodeStreamWithSettingsPreamble();
     this.ReadAheadAndSortCtorProperties();
 }
示例#5
0
文件: MeScanner.cs 项目: redmcg/wpf
 public MeScanner(XamlParserContext context, string text, int lineNumber, int linePosition)
 {
     _context                         = context;
     _inputText                       = text;
     _lineNumber                      = lineNumber;
     _startPosition                   = linePosition;
     _idx                             = -1;
     _state                           = StringState.Value;
     _currentParameterName            = null;
     _currentSpecialBracketCharacters = null;
 }
示例#6
0
 internal XamlScanner(XamlParserContext context, XmlReader xmlReader, XamlXmlReaderSettings settings)
 {
     this._xmlReader      = xmlReader;
     this._xmlLineInfo    = settings.ProvideLineInfo ? (xmlReader as IXmlLineInfo) : null;
     this._parserContext  = context;
     this._scannerStack   = new XamlScannerStack();
     this._readNodesQueue = new Queue <XamlScannerNode>();
     this._settings       = settings;
     if (settings.XmlSpacePreserve)
     {
         this._scannerStack.CurrentXmlSpacePreserve = true;
     }
 }
示例#7
0
        // This can only be done after the XmlNs's have be scanned and loaded
        public void Initialize(XamlParserContext context, XamlType tagType, string ownerNamespace, bool tagIsRoot)
        {
            // Namespaces are already flagged (but not the other kinds).
            if (Kind == ScannerAttributeKind.Namespace)
            {
                return;
            }

            Property = GetXamlAttributeProperty(context, Name, tagType, ownerNamespace, tagIsRoot);
            if (Property.IsUnknown)
            {
                Kind = ScannerAttributeKind.Unknown;
            }
            else if (Property.IsEvent)
            {
                Kind = ScannerAttributeKind.Event;
            }
            else if (Property.IsDirective)
            {
                if (Property == XamlLanguage.Space)
                {
                    Kind = ScannerAttributeKind.XmlSpace;
                }
                else if ((Property == XamlLanguage.FactoryMethod) ||
                         (Property == XamlLanguage.Arguments) ||
                         (Property == XamlLanguage.TypeArguments) ||
                         (Property == XamlLanguage.Base)
                         // || (Property == XamlLanguage.Initialization)        // doesn't appear in Xml Text
                         // || (Property == XamlLanguage.PositionalParameters)  // doesn't appear in Xml Text
                         )
                {
                    Kind = ScannerAttributeKind.CtorDirective;
                }
                else
                {
                    Kind = ScannerAttributeKind.Directive;
                }
            }
            else if (Property.IsAttachable)
            {
                Kind = ScannerAttributeKind.AttachableProperty;
            }
            else if (Property == tagType.GetAliasedProperty(XamlLanguage.Name))
            {
                Kind = ScannerAttributeKind.Name;
            }
            else
            {
                Kind = ScannerAttributeKind.Property;
            }
        }
示例#8
0
        internal XamlScanner(XamlParserContext context, XmlReader xmlReader, XamlXmlReaderSettings settings)
        {
            _xmlReader   = xmlReader;
            _xmlLineInfo = settings.ProvideLineInfo ? (xmlReader as IXmlLineInfo) : null;  //consider removing the "settings" check

            _parserContext = context;

            _scannerStack   = new XamlScannerStack();
            _readNodesQueue = new Queue <XamlScannerNode>();

            _settings = settings;
            if (settings.XmlSpacePreserve)
            {
                _scannerStack.CurrentXmlSpacePreserve = true;
            }
        }
示例#9
0
文件: MeScanner.cs 项目: redmcg/wpf
 internal BracketModeParseParameters(XamlParserContext context)
 {
     CurrentConstructorParam = 0;
     IsBracketEscapeMode     = false;
     BracketCharacterStack   = new Stack <char>();
     if (context.CurrentLongestConstructorOfMarkupExtension != null)
     {
         IsConstructorParsingMode = context.CurrentLongestConstructorOfMarkupExtension.Length > 0;
         MaxConstructorParams     = context.CurrentLongestConstructorOfMarkupExtension.Length;
     }
     else
     {
         IsConstructorParsingMode = false;
         MaxConstructorParams     = 0;
     }
 }
        private XamlMember GetXamlAttributeProperty(XamlParserContext context, XamlPropertyName propName, XamlType tagType, string tagNamespace, bool tagIsRoot)
        {
            string attributeNamespace = context.GetAttributeNamespace(propName, tagNamespace);

            if (attributeNamespace == null)
            {
                if (propName.IsDotted)
                {
                    return(new XamlMember(propName.Name, new XamlType(string.Empty, propName.OwnerName, null, context.SchemaContext), true));
                }
                return(new XamlMember(propName.Name, tagType, false));
            }
            if (propName.IsDotted)
            {
                return(context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot));
            }
            return(context.GetNoDotAttributeProperty(tagType, propName, tagNamespace, attributeNamespace, tagIsRoot));
        }
 public void Initialize(XamlParserContext context, XamlType tagType, string ownerNamespace, bool tagIsRoot)
 {
     if (this.Kind != ScannerAttributeKind.Namespace)
     {
         this.Property = this.GetXamlAttributeProperty(context, this.Name, tagType, ownerNamespace, tagIsRoot);
         if (this.Property.IsUnknown)
         {
             this.Kind = ScannerAttributeKind.Unknown;
         }
         else if (this.Property.IsEvent)
         {
             this.Kind = ScannerAttributeKind.Event;
         }
         else if (this.Property.IsDirective)
         {
             if (this.Property == XamlLanguage.Space)
             {
                 this.Kind = ScannerAttributeKind.XmlSpace;
             }
             else if (((this.Property == XamlLanguage.FactoryMethod) || (this.Property == XamlLanguage.Arguments)) || ((this.Property == XamlLanguage.TypeArguments) || (this.Property == XamlLanguage.Base)))
             {
                 this.Kind = ScannerAttributeKind.CtorDirective;
             }
             else
             {
                 this.Kind = ScannerAttributeKind.Directive;
             }
         }
         else if (this.Property.IsAttachable)
         {
             this.Kind = ScannerAttributeKind.AttachableProperty;
         }
         else if (this.Property == tagType.GetAliasedProperty(XamlLanguage.Name))
         {
             this.Kind = ScannerAttributeKind.Name;
         }
         else
         {
             this.Kind = ScannerAttributeKind.Property;
         }
     }
 }
示例#12
0
        private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
        {
            XmlReader myXmlReader;

            _mergedSettings = (settings == null) ? new XamlXmlReaderSettings() : new XamlXmlReaderSettings(settings);
            //Wrap the xmlreader with a XmlCompatReader instance to apply MarkupCompat rules.
            if (!_mergedSettings.SkipXmlCompatibilityProcessing)
            {
                XmlCompatibilityReader mcReader =
                    new XmlCompatibilityReader(givenXmlReader,
                                               new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported)
                                               );
                mcReader.Normalization = true;
                myXmlReader            = mcReader;
            }
            else
            {   //Don't wrap the xmlreader with XmlCompatReader.
                // Useful for uses where users want to keep mc: content in the XamlNode stream.
                // Or have already processed the markup compat and want that extra perf.
                myXmlReader = givenXmlReader;
            }
            // Pick up the XmlReader settings to override the "settings" defaults.
            if (!String.IsNullOrEmpty(myXmlReader.BaseURI))
            {
                _mergedSettings.BaseUri = new Uri(myXmlReader.BaseURI);
            }
            if (myXmlReader.XmlSpace == XmlSpace.Preserve)
            {
                _mergedSettings.XmlSpacePreserve = true;
            }
            if (!String.IsNullOrEmpty(myXmlReader.XmlLang))
            {
                _mergedSettings.XmlLang = myXmlReader.XmlLang;
            }
            IXmlNamespaceResolver       myXmlReaderNS   = myXmlReader as IXmlNamespaceResolver;
            Dictionary <string, string> xmlnsDictionary = null;

            if (myXmlReaderNS != null)
            {
                IDictionary <string, string> rootNamespaces = myXmlReaderNS.GetNamespacesInScope(XmlNamespaceScope.Local);
                if (rootNamespaces != null)
                {
                    foreach (KeyValuePair <string, string> ns in rootNamespaces)
                    {
                        if (xmlnsDictionary == null)
                        {
                            xmlnsDictionary = new Dictionary <string, string>();
                        }
                        xmlnsDictionary[ns.Key] = ns.Value;
                    }
                }
            }

            if (schemaContext == null)
            {
                schemaContext = new XamlSchemaContext();
            }

            _endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream);

            _context = new XamlParserContext(schemaContext, _mergedSettings.LocalAssembly);
            _context.AllowProtectedMembersOnRoot = _mergedSettings.AllowProtectedMembersOnRoot;
            _context.AddNamespacePrefix(KnownStrings.XmlPrefix, XamlLanguage.Xml1998Namespace);

            Func <string, string> namespaceResolver = myXmlReader.LookupNamespace;

            _context.XmlNamespaceResolver = namespaceResolver;

            XamlScanner    xamlScanner = new XamlScanner(_context, myXmlReader, _mergedSettings);
            XamlPullParser parser      = new XamlPullParser(_context, xamlScanner, _mergedSettings);

            _nodeStream      = new NodeStreamSorter(_context, parser, _mergedSettings, xmlnsDictionary);
            _current         = new XamlNode(XamlNode.InternalNodeType.StartOfStream); // user must call Read() before using properties.
            _currentLineInfo = new LineInfo(0, 0);
        }
 public MePullParser(XamlParserContext stack)
 {
     this._context = stack;
 }
示例#14
0
 public XamlPullParser(XamlParserContext context, XamlScanner scanner, XamlXmlReaderSettings settings)
 {
     _context     = context;
     _xamlScanner = scanner;
     _settings    = settings;
 }
        private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
        {
            XmlReader reader;

            this._mergedSettings = (settings == null) ? new XamlXmlReaderSettings() : new XamlXmlReaderSettings(settings);
            if (!this._mergedSettings.SkipXmlCompatibilityProcessing)
            {
                XmlCompatibilityReader reader2 = new XmlCompatibilityReader(givenXmlReader, new IsXmlNamespaceSupportedCallback(this.IsXmlNamespaceSupported))
                {
                    Normalization = true
                };
                reader = reader2;
            }
            else
            {
                reader = givenXmlReader;
            }
            if (!string.IsNullOrEmpty(reader.BaseURI))
            {
                this._mergedSettings.BaseUri = new Uri(reader.BaseURI);
            }
            if (reader.XmlSpace == XmlSpace.Preserve)
            {
                this._mergedSettings.XmlSpacePreserve = true;
            }
            if (!string.IsNullOrEmpty(reader.XmlLang))
            {
                this._mergedSettings.XmlLang = reader.XmlLang;
            }
            IXmlNamespaceResolver       resolver        = reader as IXmlNamespaceResolver;
            Dictionary <string, string> xmlnsDictionary = null;

            if (resolver != null)
            {
                IDictionary <string, string> namespacesInScope = resolver.GetNamespacesInScope(XmlNamespaceScope.Local);
                if (namespacesInScope != null)
                {
                    foreach (KeyValuePair <string, string> pair in namespacesInScope)
                    {
                        if (xmlnsDictionary == null)
                        {
                            xmlnsDictionary = new Dictionary <string, string>();
                        }
                        xmlnsDictionary[pair.Key] = pair.Value;
                    }
                }
            }
            if (schemaContext == null)
            {
                schemaContext = new XamlSchemaContext();
            }
            this._endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream);
            this._context         = new XamlParserContext(schemaContext, this._mergedSettings.LocalAssembly);
            this._context.AllowProtectedMembersOnRoot = this._mergedSettings.AllowProtectedMembersOnRoot;
            this._context.AddNamespacePrefix("xml", "http://www.w3.org/XML/1998/namespace");
            Func <string, string> func = new Func <string, string>(reader.LookupNamespace);

            this._context.XmlNamespaceResolver = func;
            XamlScanner    scanner = new XamlScanner(this._context, reader, this._mergedSettings);
            XamlPullParser parser  = new XamlPullParser(this._context, scanner, this._mergedSettings);

            this._nodeStream      = new NodeStreamSorter(this._context, parser, this._mergedSettings, xmlnsDictionary);
            this._current         = new XamlNode(XamlNode.InternalNodeType.StartOfStream);
            this._currentLineInfo = new System.Xaml.LineInfo(0, 0);
        }