예제 #1
0
 /// <summary>
 /// Create a BamlWriter on the passed stream.  The stream must be writable.
 /// </summary>
 public BamlWriter(
     Stream stream)
 {
     if (null == stream)
     {
         throw new ArgumentNullException( "stream" );
     }
     if (!stream.CanWrite)
     {
         throw new ArgumentException(SR.Get(SRID.BamlWriterBadStream));
     }
     
     _parserContext = new ParserContext();
     if (null == _parserContext.XamlTypeMapper) 
     {
         _parserContext.XamlTypeMapper = new BamlWriterXamlTypeMapper(XmlParserDefaults.GetDefaultAssemblyNames(),
                                                                      XmlParserDefaults.GetDefaultNamespaceMaps());
     }
     _xamlTypeMapper = _parserContext.XamlTypeMapper;
     _bamlRecordWriter = new BamlRecordWriter(stream, _parserContext, true);
     _startDocumentWritten = false;
     _depth = 0;
     _closed = false;
     _nodeTypeStack = new ParserStack();
     _assemblies = new Hashtable(7);
    _extensionParser = new MarkupExtensionParser((IParserHelper)this, _parserContext);
    _markupExtensionNodes = new ArrayList();
 }
        /// <summary>
        /// Constructor. Internal so only the XamlParser and select
        /// Avalon object parsers can call it.
        /// </summary>
        internal XamlReaderHelper(
            XamlParser xamlParser,
            ParserContext parserContext,
            XmlReader xmlReader)
        {

            Debug.Assert(xamlParser != null, "Cannot have null xaml parser");
            Debug.Assert(parserContext != null, "Cannot have null parser context");
            Debug.Assert(xmlReader != null, "Cannot have null xmlReader");

            // use the parser class for making resolution callbacks. for GetElementBaseType
            // probably should break that call + the XamlTypeMapper calls into an interface to
            // comletely abstract the resolution from the tokenizer.
            _xamlParser = xamlParser;
            _parserContext = parserContext;

            XmlReader = xmlReader;
            Normalization = true;

            _xamlNodeCollectionProcessor = new XamlNodeCollectionProcessor();

            // setup the _textFlow stack
            _textFlowStack = new Stack();

            // push a rootLevel stack
            // !! Todo. Need a way for caller of the parser to set how
            // the root text should be handled. For now always use InlineBlock.
            TextFlowStackData textFlowStackData = new TextFlowStackData();
            textFlowStackData.StripLeadingSpaces = true;

            TextFlowStack.Push(textFlowStackData);

            _extensionParser = new MarkupExtensionParser((IParserHelper)this, parserContext);

#if UseValidatingReader
            // turn on to setup validating Reader.
            XmlValidatingReader xmlValidatingReader = new XmlValidatingReader(xmlReader);
            xmlValidatingReader.ValidationType = ValidationType.None;
            XmlReader = xmlValidatingReader;

#endif // UseValidatingReader

        }