private static Res GetLoader() { if (loader == null) { Res res = new Res(); Interlocked.CompareExchange<Res>(ref loader, res, null); } return loader; }
internal XmlReader AddConformanceWrapper(XmlReader baseReader) { XmlReaderSettings baseReaderSettings = baseReader.Settings; bool checkChars = false; bool noWhitespace = false; bool noComments = false; bool noPIs = false; DtdProcessing dtdProc = (DtdProcessing)(-1); bool needWrap = false; if (baseReaderSettings == null) { #pragma warning disable 618 #if SILVERLIGHT // Starting from Windows phone 8.1 (TargetsAtLeast_Desktop_V4_5_1) we converge with the desktop behavior so we'll let the reader // not throw exception if has different conformance level than Auto. if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5_1) { if (this.conformanceLevel != ConformanceLevel.Auto && this.conformanceLevel != XmlReader.GetV1ConformanceLevel(baseReader)) { throw new InvalidOperationException(Res.GetString(Res.Xml_IncompatibleConformanceLevel, this.conformanceLevel.ToString())); } } else if (this.conformanceLevel != ConformanceLevel.Auto) { throw new InvalidOperationException(Res.GetString(Res.Xml_IncompatibleConformanceLevel, this.conformanceLevel.ToString())); } #else if (this.conformanceLevel != ConformanceLevel.Auto && this.conformanceLevel != XmlReader.GetV1ConformanceLevel(baseReader)) { throw new InvalidOperationException(Res.GetString(Res.Xml_IncompatibleConformanceLevel, this.conformanceLevel.ToString())); } #endif #if !SILVERLIGHT // get the V1 XmlTextReader ref XmlTextReader v1XmlTextReader = baseReader as XmlTextReader; if (v1XmlTextReader == null) { XmlValidatingReader vr = baseReader as XmlValidatingReader; if (vr != null) { v1XmlTextReader = (XmlTextReader)vr.Reader; } } #endif // assume the V1 readers already do all conformance checking; // wrap only if IgnoreWhitespace, IgnoreComments, IgnoreProcessingInstructions or ProhibitDtd is true; if (this.ignoreWhitespace) { WhitespaceHandling wh = WhitespaceHandling.All; #if !SILVERLIGHT // special-case our V1 readers to see if whey already filter whitespaces if (v1XmlTextReader != null) { wh = v1XmlTextReader.WhitespaceHandling; } #endif if (wh == WhitespaceHandling.All) { noWhitespace = true; needWrap = true; } } if (this.ignoreComments) { noComments = true; needWrap = true; } if (this.ignorePIs) { noPIs = true; needWrap = true; } // DTD processing DtdProcessing baseDtdProcessing = DtdProcessing.Parse; #if !SILVERLIGHT if (v1XmlTextReader != null) { baseDtdProcessing = v1XmlTextReader.DtdProcessing; } #endif if ((this.dtdProcessing == DtdProcessing.Prohibit && baseDtdProcessing != DtdProcessing.Prohibit) || (this.dtdProcessing == DtdProcessing.Ignore && baseDtdProcessing == DtdProcessing.Parse)) { dtdProc = this.dtdProcessing; needWrap = true; } #pragma warning restore 618 } else { if (this.conformanceLevel != baseReaderSettings.ConformanceLevel && this.conformanceLevel != ConformanceLevel.Auto) { throw new InvalidOperationException(Res.GetString(Res.Xml_IncompatibleConformanceLevel, this.conformanceLevel.ToString())); } if (this.checkCharacters && !baseReaderSettings.CheckCharacters) { checkChars = true; needWrap = true; } if (this.ignoreWhitespace && !baseReaderSettings.IgnoreWhitespace) { noWhitespace = true; needWrap = true; } if (this.ignoreComments && !baseReaderSettings.IgnoreComments) { noComments = true; needWrap = true; } if (this.ignorePIs && !baseReaderSettings.IgnoreProcessingInstructions) { noPIs = true; needWrap = true; } if ((this.dtdProcessing == DtdProcessing.Prohibit && baseReaderSettings.DtdProcessing != DtdProcessing.Prohibit) || (this.dtdProcessing == DtdProcessing.Ignore && baseReaderSettings.DtdProcessing == DtdProcessing.Parse)) { dtdProc = this.dtdProcessing; needWrap = true; } } if (needWrap) { IXmlNamespaceResolver readerAsNSResolver = baseReader as IXmlNamespaceResolver; if (readerAsNSResolver != null) { return(new XmlCharCheckingReaderWithNS(baseReader, readerAsNSResolver, checkChars, noWhitespace, noComments, noPIs, dtdProc)); } else { return(new XmlCharCheckingReader(baseReader, checkChars, noWhitespace, noComments, noPIs, dtdProc)); } } else { return(baseReader); } }