Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / Dom / XmlSignificantWhiteSpace.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlSignificantWhiteSpace.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 namespace System.Xml
9 {
10     using System;
11     using System.Xml.XPath;
12     using System.Text;
13     using System.Diagnostics;
14
15     // Represents the text content of an element or attribute.
16     public class XmlSignificantWhitespace : XmlCharacterData {
17         protected internal XmlSignificantWhitespace( string strData, XmlDocument doc ) : base( strData, doc ) {
18             if ( !doc.IsLoading && !base.CheckOnData( strData ) )
19                 throw new ArgumentException(Res.GetString(Res.Xdom_WS_Char));
20         }
21
22         // Gets the name of the node.
23         public override String Name {
24             get { 
25                 return OwnerDocument.strSignificantWhitespaceName;
26             }
27         }
28
29         // Gets the name of the current node without the namespace prefix.
30         public override String LocalName {
31             get { 
32                 return OwnerDocument.strSignificantWhitespaceName;
33             }
34         }
35
36         // Gets the type of the current node.
37         public override XmlNodeType NodeType {
38             get { 
39                 return XmlNodeType.SignificantWhitespace;
40             }
41         }
42
43         public override XmlNode ParentNode {
44             get {
45                 switch (parentNode.NodeType) {
46                     case XmlNodeType.Document:
47                         return base.ParentNode;
48                     case XmlNodeType.Text:
49                     case XmlNodeType.CDATA:
50                     case XmlNodeType.Whitespace:
51                     case XmlNodeType.SignificantWhitespace:
52                         XmlNode parent = parentNode.parentNode;
53                         while (parent.IsText) {
54                             parent = parent.parentNode;
55                         }
56                         return parent; 
57                     default:
58                         return parentNode;
59                 }
60             }
61         }
62
63         // Creates a duplicate of this node.
64         public override XmlNode CloneNode(bool deep) {
65             Debug.Assert( OwnerDocument != null );
66             return OwnerDocument.CreateSignificantWhitespace( Data );
67         }
68
69         public override String Value {
70             get { 
71                 return Data;
72             }
73
74             set {
75                 if ( CheckOnData( value ) )
76                     Data = value;
77                 else
78                     throw new ArgumentException(Res.GetString(Res.Xdom_WS_Char));
79             }
80         }
81
82         // Saves the node to the specified XmlWriter.
83         public override void WriteTo(XmlWriter w) {
84             w.WriteString(Data);
85         }
86
87         // Saves all the children of the node to the specified XmlWriter.
88         public override void WriteContentTo(XmlWriter w) {
89             // Intentionally do nothing
90         }
91
92         internal override XPathNodeType XPNodeType {
93             get {
94                 XPathNodeType xnt = XPathNodeType.SignificantWhitespace;
95                 DecideXPNodeTypeForTextNodes(this, ref xnt);
96                 return xnt;
97             }
98         }
99
100         internal override bool IsText {
101             get {
102                 return true;
103             }
104         }
105
106         public override XmlNode PreviousText {
107             get {
108                 if (parentNode.IsText) {
109                     return parentNode;
110                 }
111                 return null;
112             }
113         }
114     }
115 }