XamlWrapperReaders.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Debugger / XamlWrapperReaders.cs / 1305376 / XamlWrapperReaders.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.Activities.Debugger 
{
    using System.Collections.Generic; 
    using System.Diagnostics.CodeAnalysis; 
    using System.Xml.Linq;
    using System.Xaml; 
    using System.Xaml.Schema;
    using System.Runtime;
    using System.Text;
    using System.Globalization; 
    using System.Linq;
    using System.Windows.Markup; 
    using System.Xml; 
    using System.ComponentModel;
 
    class XamlValidatingReader
    {
        XamlReader reader;
        IXamlLineInfo xamlLineInfo; 
        Stack nodes;
        int lastLineNumber; 
        int lastLinePosition; 
        XamlNode current;
 
        public XamlValidatingReader(XamlReader reader, IXamlLineInfo xamlLineInfo)
        {
            this.reader = reader;
            this.xamlLineInfo = xamlLineInfo; 
            this.nodes = new Stack();
        } 
 
        public bool Read()
        { 
            if (!this.reader.Read())
            {
                return false;
            } 

            this.current = CreateSpecializedNode(); 
 
            // xamlReader surfaces 0 for LineNumber and LinePosition
            // when the node type is GetObject, EndObject, EndMember, and Value 

            if (this.current.LineNumber == 0 || this.current.LinePosition == 0)
            {
                this.current.LineNumber = lastLineNumber; 
                this.current.LinePosition = lastLinePosition;
            } 
            else 
            {
                lastLineNumber = this.current.LineNumber; 
                lastLinePosition = this.current.LinePosition;
            }

            return true; 
        }
 
        public bool EndOfInput 
        {
            get 
            {
                return reader.IsEof;
            }
        } 

        public XamlNode Current 
        { 
            get
            { 
                return this.current;
            }
        }
 
        XamlNode CreateSpecializedNode()
        { 
            XamlNode node = null; 
            switch (this.reader.NodeType)
            { 
                case XamlNodeType.StartObject:
                    node = CreateXamlStartRecordNode();
                    break;
                case XamlNodeType.GetObject: 
                    node = CreateXamlGetObjectNode();
                    break; 
                case XamlNodeType.StartMember: 
                    node = CreateXamlStartMemberNode();
                    break; 
                case XamlNodeType.EndMember:
                    node = CreateXamlEndMemberNode();
                    break;
                case XamlNodeType.EndObject: 
                    node = CreateXamlEndRecordNode();
                    break; 
                case XamlNodeType.Value: 
                    node = CreateXamlAtomNode();
                    break; 
                case XamlNodeType.NamespaceDeclaration:
                    node = CreateXamlNamespaceNode();
                    break;
                default: 
                    break;
            } 
 
            return node;
        } 

        XamlNode CreateXamlNamespaceNode()
        {
            XamlNamespaceNode namespaceNode = new XamlNamespaceNode() 
            {
                Namespace = this.reader.Namespace, 
            }; 
            return namespaceNode;
        } 

        XamlNode CreateXamlStartRecordNode()
        {
            XamlStartRecordNode record = new XamlStartRecordNode() 
            {
                LineNumber = this.xamlLineInfo.LineNumber, 
                LinePosition = this.xamlLineInfo.LinePosition, 
                TypeName = XName.Get(this.reader.Type.Name, this.reader.Type.PreferredXamlNamespace),
                RecordType = this.reader.Type 
            };

            this.nodes.Push(record);
            return record; 
        }
 
        XamlNode CreateXamlGetObjectNode() 
        {
            XamlGetObjectNode node = new XamlGetObjectNode() 
            {
                LineNumber = this.xamlLineInfo.LineNumber,
                LinePosition = this.xamlLineInfo.LinePosition
            }; 

            this.nodes.Push(node); 
            return node; 
        }
 
        XamlNode CreateXamlStartMemberNode()
        {
            XamlStartMemberNode member = new XamlStartMemberNode()
            { 
                LinePosition = this.xamlLineInfo.LinePosition,
                LineNumber = this.xamlLineInfo.LineNumber, 
                RecordType = this.reader.Member.Type, 
                Member = this.reader.Member
            }; 
            this.nodes.Push(member);
            return member;
        }
 
        XamlNode CreateXamlEndRecordNode()
        { 
            XamlNode node = this.nodes.Pop(); 

            XamlStartRecordNode startRecord = node as XamlStartRecordNode; 

            //startRecord might be null because node might be XamlGetObjectNode

            XamlEndRecordNode endRecord = new XamlEndRecordNode() 
            {
                LineNumber = this.xamlLineInfo.LineNumber, 
                LinePosition = this.xamlLineInfo.LinePosition, 
                TypeName = startRecord != null ? startRecord.TypeName : null,
                RecordType = startRecord != null ? startRecord.RecordType : null 
            };
            return endRecord;
        }
 
        XamlNode CreateXamlEndMemberNode()
        { 
            XamlStartMemberNode startMember = (XamlStartMemberNode)this.nodes.Pop(); 
            XamlEndMemberNode endMember = new XamlEndMemberNode()
            { 
                LinePosition = this.xamlLineInfo.LinePosition,
                LineNumber = this.xamlLineInfo.LineNumber,
                RecordType = startMember.RecordType,
                Member = startMember.Member 
            };
            return endMember; 
        } 

        XamlNode CreateXamlAtomNode() 
        {
            XamlAtomNode atom = new XamlAtomNode()
            {
                LineNumber = this.xamlLineInfo.LineNumber, 
                LinePosition = this.xamlLineInfo.LinePosition,
                Value = this.reader.Value 
            }; 
            return atom;
        } 
    }

    abstract class XamlNode : IXmlLineInfo
    { 
        protected XamlNode()
        { 
            LineNumber = 0; 
            LinePosition = 0;
        } 

        public abstract XamlNodeType NodeType
        {
            get; 
        }
 
        public Uri BaseUri 
        {
            get; 
            set;
        }

        public string XmlLang 
        {
            get; 
            set; 
        }
 
        public int LineNumber
        {
            get;
            set; 
        }
 
        public int LinePosition 
        {
            get; 
            set;
        }

        [Fx.Tag.NonThrowing] 
        public bool HasLineInfo()
        { 
            return LineNumber != -1 && LinePosition != -1; 
        }
    } 

    class XamlNamespaceNode : XamlNode
    {
        public XamlNamespaceNode() 
        {
        } 
 
        public XamlNamespaceNode(NamespaceDeclaration @namespace)
        { 
            this.Namespace = @namespace;
        }

        public NamespaceDeclaration Namespace 
        {
            get; 
            set; 
        }
 
        public sealed override XamlNodeType NodeType
        {
            get
            { 
                return XamlNodeType.NamespaceDeclaration;
            } 
        } 

    } 

    class XamlStartRecordNode : XamlNode
    {
        public XamlStartRecordNode() 
        {
        } 
 
        public sealed override XamlNodeType NodeType
        { 
            get
            {
                return XamlNodeType.StartObject;
            } 
        }
 
        public XName TypeName 
        {
            get; 
            set;
        }

        public override string ToString() 
        {
            string typeNameString = this.TypeName != null ? this.TypeName.ToString() : String.Empty; 
            return string.Format(CultureInfo.CurrentCulture, "{0}:{1}", this.NodeType, typeNameString); 
        }
 
        public XamlType RecordType
        {
            get;
            set; 
        }
    } 
 
    class XamlGetObjectNode : XamlNode
    { 
        public XamlGetObjectNode()
        {
        }
 
        public sealed override XamlNodeType NodeType
        { 
            get 
            {
                return XamlNodeType.GetObject; 
            }
        }
    }
 
    class XamlAtomNode : XamlNode
    { 
        public XamlAtomNode() 
        {
        } 

        public sealed override XamlNodeType NodeType
        {
            get 
            {
                return XamlNodeType.Value; 
            } 
        }
 
        public virtual object Value
        {
            get;
            set; 
        }
 
        public override string ToString() 
        {
            object value = Value ?? String.Empty; 
            return string.Format(CultureInfo.CurrentCulture, "{0}:{1}", this.NodeType, value.ToString());
        }
    }
 
    class XamlEndMemberNode : XamlNode
    { 
        public XamlEndMemberNode() 
        {
        } 

        public sealed override XamlNodeType NodeType
        {
            get 
            {
                return XamlNodeType.EndMember; 
            } 
        }
 
        public override string ToString()
        {
            string memberIdentifierString = this.Member != null ? this.Member.ToString() : String.Empty;
            return string.Format(CultureInfo.CurrentCulture, "{0}:{1}", this.NodeType, memberIdentifierString); 
        }
 
        public XamlType RecordType 
        {
            get; 
            set;
        }

        public XamlMember Member 
        {
            get; 
            set; 
        }
    } 

    class XamlEndRecordNode : XamlNode
    {
        public XamlEndRecordNode() 
        {
        } 
 
        public sealed override XamlNodeType NodeType
        { 
            get
            {
                return XamlNodeType.EndObject;
            } 
        }
        public XName TypeName 
        { 
            get;
            set; 
        }

        public override string ToString()
        { 
            string typeNameString = this.TypeName != null ? this.TypeName.ToString() : String.Empty;
            return string.Format(CultureInfo.CurrentCulture, "{0}:{1}", this.NodeType, typeNameString); 
        } 

        public XamlType RecordType 
        {
            get;
            set;
        } 
    }
 
    class XamlStartMemberNode : XamlNode 
    {
        public XamlStartMemberNode() 
        {
        }

        public sealed override XamlNodeType NodeType 
        {
            get 
            { 
                return XamlNodeType.StartMember;
            } 
        }

        public override string ToString()
        { 
            string memberIdentifierString = this.Member != null ? this.Member.ToString() : String.Empty;
            return string.Format(CultureInfo.CurrentCulture, "{0}:{1}", this.NodeType, memberIdentifierString); 
        } 

        public XamlType RecordType 
        {
            get;
            set;
        } 

        public XamlMember Member 
        { 
            get;
            set; 
        }
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK