From 5ba46dbbb20627f2e4d01b1b2794b0f9d118bd1c Mon Sep 17 00:00:00 2001 From: hrrrrustic Date: Mon, 12 Apr 2021 14:15:11 +0300 Subject: [PATCH 1/3] readonly annotation --- .../src/System/Xml/BinaryXml/SqlUtils.cs | 10 +-- .../System/Xml/BinaryXml/XmlBinaryReader.cs | 20 +++--- .../System/Xml/Cache/XPathDocumentBuilder.cs | 12 ++-- .../src/System/Xml/Cache/XPathNode.cs | 64 +++++++++---------- .../src/System/Xml/Core/XmlEventCache.cs | 10 +-- .../src/System/Xml/Core/XmlReader.cs | 2 +- .../Xml/Core/XmlTextReaderImplHelpers.cs | 4 +- .../Xml/Core/XmlWellFormedWriterHelpers.cs | 8 +-- .../Core/XmlWellFormedWriterHelpersAsync.cs | 6 +- .../Dom/XmlNamedNodeMap.SmallXmlNodeList.cs | 6 +- .../src/System/Xml/Schema/FacetChecker.cs | 8 +-- .../src/System/Xml/Schema/XsdDateTime.cs | 32 +++++----- .../src/System/Xml/Schema/XsdDuration.cs | 24 +++---- .../System/Xml/Serialization/XmlSerializer.cs | 8 +-- .../System/Xml/XPath/Internal/LogicalExpr.cs | 2 +- .../src/System/Xml/XPath/XPathNavigator.cs | 2 +- .../Xml/Xsl/IlGen/IteratorDescriptor.cs | 14 ++-- .../src/System/Xml/Xsl/ListBase.cs | 2 +- .../src/System/Xml/Xsl/Pair.cs | 12 ++-- .../Xml/Xsl/Runtime/ContentIterators.cs | 14 ++-- .../System/Xml/Xsl/Runtime/SetIterators.cs | 6 +- .../Xml/Xsl/Runtime/SiblingIterators.cs | 8 +-- .../System/Xml/Xsl/Runtime/StringConcat.cs | 6 +- .../System/Xml/Xsl/Runtime/TreeIterators.cs | 24 +++---- .../System/Xml/Xsl/Runtime/XmlAggregates.cs | 40 ++++++------ .../Xml/Xsl/Runtime/XmlAttributeCache.cs | 12 ++-- .../System/Xml/Xsl/Runtime/XmlCollation.cs | 14 ++-- .../System/Xml/Xsl/Runtime/XmlIterators.cs | 2 +- .../Xml/Xsl/Runtime/XmlNavigatorStack.cs | 4 +- .../Xml/Xsl/Runtime/XmlSortKeyAccumulator.cs | 2 +- .../src/System/Xml/Xsl/SourceLineInfo.cs | 6 +- .../src/System/Xml/Xsl/XPathConvert.cs | 4 +- .../src/System/Xml/Xsl/XmlQueryCardinality.cs | 16 ++--- .../Xml/Xsl/Xslt/CompilerScopeManager.cs | 6 +- .../src/System/Xml/Xsl/Xslt/Focus.cs | 22 +++---- .../src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs | 2 +- .../src/System/Xml/Xsl/Xslt/XsltInput.cs | 2 +- .../src/System/Xml/Xsl/XsltOld/RootAction.cs | 4 +- 38 files changed, 220 insertions(+), 220 deletions(-) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/SqlUtils.cs b/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/SqlUtils.cs index a88f9cfde36f4..cdc5535797878 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/SqlUtils.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/SqlUtils.cs @@ -23,7 +23,7 @@ internal struct BinXmlSqlDecimal internal uint m_data3; internal uint m_data4; - public bool IsPositive + public readonly bool IsPositive { get { @@ -139,7 +139,7 @@ private static char ChFromDigit(uint uiDigit) return (char)(uiDigit + '0'); } - public decimal ToDecimal() + public readonly decimal ToDecimal() { if ((int)m_data4 != 0 || m_bScale > 28) throw new XmlException(SR.SqlTypes_ArithOverflow, (string?)null); @@ -246,7 +246,7 @@ public override string ToString() // Is this RE numeric valid? [System.Diagnostics.Conditional("DEBUG")] - private void AssertValid() + private readonly void AssertValid() { // Scale,Prec in range Debug.Assert(m_bScale <= s_NUMERIC_MAX_PRECISION, "m_bScale <= NUMERIC_MAX_PRECISION", "In AssertValid"); @@ -277,7 +277,7 @@ internal struct BinXmlSqlMoney public BinXmlSqlMoney(int v) { _data = v; } public BinXmlSqlMoney(long v) { _data = v; } - public decimal ToDecimal() + public readonly decimal ToDecimal() { bool neg; ulong v; @@ -296,7 +296,7 @@ public decimal ToDecimal() return new decimal(unchecked((int)v), unchecked((int)(v >> 32)), 0, neg, MoneyScale); } - public override string ToString() + public override readonly string ToString() { decimal money = ToDecimal(); // Formatting of SqlMoney: At least two digits after decimal point diff --git a/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs index 36d739c9dae89..91f247b0c96af 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs @@ -79,34 +79,34 @@ public void Clear() this.prefix = this.localname = this.namespaceUri = string.Empty; } - public bool MatchNs(string lname, string nsUri) + public readonly bool MatchNs(string lname, string nsUri) { return lname == this.localname && nsUri == this.namespaceUri; } - public bool MatchPrefix(string prefix, string lname) + public readonly bool MatchPrefix(string prefix, string lname) { return lname == this.localname && prefix == this.prefix; } - public void CheckPrefixNS(string prefix, string namespaceUri) + public readonly void CheckPrefixNS(string prefix, string namespaceUri) { if (this.prefix == prefix && this.namespaceUri != namespaceUri) throw new XmlException(SR.XmlBinary_NoRemapPrefix, new string[] { prefix, this.namespaceUri, namespaceUri }); } - public override int GetHashCode() + public override readonly int GetHashCode() { return this.prefix.GetHashCode() ^ this.localname.GetHashCode(); } - public int GetNSHashCode() + public readonly int GetNSHashCode() { return HashCode.Combine(this.namespaceUri, this.localname); } - public override bool Equals([NotNullWhen(true)] object? other) + public override readonly bool Equals([NotNullWhen(true)] object? other) { if (other is QName that) { @@ -115,7 +115,7 @@ public override bool Equals([NotNullWhen(true)] object? other) return false; } - public override string ToString() + public override readonly string ToString() { if (prefix.Length == 0) return this.localname; @@ -185,7 +185,7 @@ public void Set(QName n, int pos) this.prevHash = 0; } - public void GetLocalnameAndNamespaceUri(out string localname, out string namespaceUri) + public readonly void GetLocalnameAndNamespaceUri(out string localname, out string namespaceUri) { localname = this.name.localname; namespaceUri = this.name.namespaceUri; @@ -198,12 +198,12 @@ public int GetLocalnameAndNamespaceUriAndHash(out string localname, out string n return this.hashCode = this.name.GetNSHashCode(); } - public bool MatchNS(string localname, string namespaceUri) + public readonly bool MatchNS(string localname, string namespaceUri) { return this.name.MatchNs(localname, namespaceUri); } - public bool MatchHashNS(int hash, string localname, string namespaceUri) + public readonly bool MatchHashNS(int hash, string localname, string namespaceUri) { return this.hashCode == hash && this.name.MatchNs(localname, namespaceUri); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentBuilder.cs index 41c65bd432a18..f4b25bfcd8893 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentBuilder.cs @@ -807,7 +807,7 @@ public void Init(int initialPageSize) /// /// Return the page on which the next node will be allocated. /// - public XPathNode[] NextNodePage + public readonly XPathNode[] NextNodePage { get { return _page; } } @@ -815,7 +815,7 @@ public XPathNode[] NextNodePage /// /// Return the page index that the next node will be given. /// - public int NextNodeIndex + public readonly int NextNodeIndex { get { return _pageInfo.NodeCount; } } @@ -867,7 +867,7 @@ public void Initialize(IXmlLineInfo? lineInfo) /// /// Return the type of the cached text block. /// - public TextBlockType TextType + public readonly TextBlockType TextType { get { return _textType; } } @@ -875,7 +875,7 @@ public TextBlockType TextType /// /// Returns true if text has been cached. /// - public bool HasText + public readonly bool HasText { get { return _textType != TextBlockType.None; } } @@ -883,7 +883,7 @@ public bool HasText /// /// Returns the line number of the last text block to be cached. /// - public int LineNumber + public readonly int LineNumber { get { return _lineNum; } } @@ -891,7 +891,7 @@ public int LineNumber /// /// Returns the line position of the last text block to be cached. /// - public int LinePosition + public readonly int LinePosition { get { return _linePos; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNode.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNode.cs index 30e93b6242915..3cd808f4f07f8 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNode.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNode.cs @@ -60,7 +60,7 @@ internal struct XPathNode /// /// Returns the type of this node /// - public XPathNodeType NodeType + public readonly XPathNodeType NodeType { get { return (XPathNodeType)(_props & NodeTypeMask); } } @@ -69,7 +69,7 @@ public XPathNodeType NodeType /// Returns the namespace prefix of this node. If this node has no prefix, then the empty string /// will be returned (never null). /// - public string Prefix + public readonly string Prefix { get { return _info.Prefix; } } @@ -78,7 +78,7 @@ public string Prefix /// Returns the local name of this node. If this node has no name, then the empty string /// will be returned (never null). /// - public string LocalName + public readonly string LocalName { get { return _info.LocalName; } } @@ -87,7 +87,7 @@ public string LocalName /// Returns the name of this node. If this node has no name, then the empty string /// will be returned (never null). /// - public string Name + public readonly string Name { get { @@ -106,7 +106,7 @@ public string Name /// Returns the namespace part of this node's name. If this node has no name, then the empty string /// will be returned (never null). /// - public string NamespaceUri + public readonly string NamespaceUri { get { return _info.NamespaceUri; } } @@ -114,7 +114,7 @@ public string NamespaceUri /// /// Returns this node's document. /// - public XPathDocument Document + public readonly XPathDocument Document { get { return _info.Document; } } @@ -122,7 +122,7 @@ public XPathDocument Document /// /// Returns this node's base Uri. This is string.Empty for all node kinds except Element, Root, and PI. /// - public string BaseUri + public readonly string BaseUri { get { return _info.BaseUri ?? string.Empty; } } @@ -130,7 +130,7 @@ public string BaseUri /// /// Returns this node's source line number. /// - public int LineNumber + public readonly int LineNumber { get { return _info.LineNumberBase + (int)((_props & LineNumberMask) >> LineNumberShift); } } @@ -138,7 +138,7 @@ public int LineNumber /// /// Return this node's source line position. /// - public int LinePosition + public readonly int LinePosition { get { return _info.LinePositionBase + (int)_posOffset; } } @@ -147,7 +147,7 @@ public int LinePosition /// If this node is an element with collapsed text, then return the source line position of the node (the /// source line number is the same as LineNumber). /// - public int CollapsedLinePosition + public readonly int CollapsedLinePosition { get { @@ -159,7 +159,7 @@ public int CollapsedLinePosition /// /// Returns information about the node page. Only the 0th node on each page has this property defined. /// - public XPathNodePageInfo? PageInfo + public readonly XPathNodePageInfo? PageInfo { get { return _info.PageInfo; } } @@ -167,7 +167,7 @@ public XPathNodePageInfo? PageInfo /// /// Returns the root node of the current document. This always succeeds. /// - public int GetRoot(out XPathNode[] pageNode) + public readonly int GetRoot(out XPathNode[] pageNode) { int idx = _info.Document.GetRootNode(out pageNode!); Debug.Assert(pageNode != null); @@ -177,7 +177,7 @@ public int GetRoot(out XPathNode[] pageNode) /// /// Returns the parent of this node. If this node has no parent, then 0 is returned. /// - public int GetParent(out XPathNode[]? pageNode) + public readonly int GetParent(out XPathNode[]? pageNode) { pageNode = _info.ParentPage; return _idxParent; @@ -186,7 +186,7 @@ public int GetParent(out XPathNode[]? pageNode) /// /// Returns the next sibling of this node. If this node has no next sibling, then 0 is returned. /// - public int GetSibling(out XPathNode[]? pageNode) + public readonly int GetSibling(out XPathNode[]? pageNode) { pageNode = _info.SiblingPage; return _idxSibling; @@ -196,7 +196,7 @@ public int GetSibling(out XPathNode[]? pageNode) /// Returns the next element in document order that has the same local name hashcode as this element. /// If there are no similar elements, then 0 is returned. /// - public int GetSimilarElement(out XPathNode[]? pageNode) + public readonly int GetSimilarElement(out XPathNode[]? pageNode) { pageNode = _info.SimilarElementPage; return _idxSimilar; @@ -206,7 +206,7 @@ public int GetSimilarElement(out XPathNode[]? pageNode) /// Returns true if this node's name matches the specified localName and namespaceName. Assume /// that localName has been atomized, but namespaceName has not. /// - public bool NameMatch(string? localName, string namespaceName) + public readonly bool NameMatch(string? localName, string namespaceName) { Debug.Assert(localName == null || (object?)Document.NameTable.Get(localName) == (object)localName, "localName must be atomized."); @@ -218,7 +218,7 @@ public bool NameMatch(string? localName, string namespaceName) /// Returns true if this is an Element node with a name that matches the specified localName and /// namespaceName. Assume that localName has been atomized, but namespaceName has not. /// - public bool ElementMatch(string? localName, string namespaceName) + public readonly bool ElementMatch(string? localName, string namespaceName) { Debug.Assert(localName == null || (object?)Document.NameTable.Get(localName) == (object)localName, "localName must be atomized."); @@ -230,7 +230,7 @@ public bool ElementMatch(string? localName, string namespaceName) /// /// Return true if this node is an xmlns:xml node. /// - public bool IsXmlNamespaceNode + public readonly bool IsXmlNamespaceNode { get { @@ -242,7 +242,7 @@ public bool IsXmlNamespaceNode /// /// Returns true if this node has a sibling. /// - public bool HasSibling + public readonly bool HasSibling { get { return _idxSibling != 0; } } @@ -250,7 +250,7 @@ public bool HasSibling /// /// Returns true if this node has a collapsed text node as its only content-typed child. /// - public bool HasCollapsedText + public readonly bool HasCollapsedText { get { return (_props & HasCollapsedTextBit) != 0; } } @@ -258,7 +258,7 @@ public bool HasCollapsedText /// /// Returns true if this node has at least one attribute. /// - public bool HasAttribute + public readonly bool HasAttribute { get { return (_props & HasAttributeBit) != 0; } } @@ -267,7 +267,7 @@ public bool HasAttribute /// Returns true if this node has at least one content-typed child (attributes and namespaces /// don't count). /// - public bool HasContentChild + public readonly bool HasContentChild { get { return (_props & HasContentChildBit) != 0; } } @@ -275,7 +275,7 @@ public bool HasContentChild /// /// Returns true if this node has at least one element child. /// - public bool HasElementChild + public readonly bool HasElementChild { get { return (_props & HasElementChildBit) != 0; } } @@ -283,7 +283,7 @@ public bool HasElementChild /// /// Returns true if this is an attribute or namespace node. /// - public bool IsAttrNmsp + public readonly bool IsAttrNmsp { get { @@ -295,7 +295,7 @@ public bool IsAttrNmsp /// /// Returns true if this is a text or whitespace node. /// - public bool IsText + public readonly bool IsText { get { return XPathNavigator.IsText(NodeType); } } @@ -308,7 +308,7 @@ public bool IsText /// public bool HasNamespaceDecls { - get { return (_props & HasNmspDeclsBit) != 0; } + readonly get { return (_props & HasNmspDeclsBit) != 0; } set { if (value) _props |= HasNmspDeclsBit; @@ -319,7 +319,7 @@ public bool HasNamespaceDecls /// /// Returns true if this node is an empty element that allows shortcut tag syntax. /// - public bool AllowShortcutTag + public readonly bool AllowShortcutTag { get { return (_props & AllowShortcutTagBit) != 0; } } @@ -327,7 +327,7 @@ public bool AllowShortcutTag /// /// Cached hashcode computed over the local name of this element. /// - public int LocalNameHashCode + public readonly int LocalNameHashCode { get { return _info.LocalNameHashCode; } } @@ -335,7 +335,7 @@ public int LocalNameHashCode /// /// Return the precomputed String value of this node (null if no value exists, i.e. document node, element node with complex content, etc). /// - public string? Value + public readonly string? Value { get { return _value; } } @@ -485,17 +485,17 @@ public XPathNodeRef(XPathNode[] page, int idx) _idx = idx; } - public XPathNode[] Page + public readonly XPathNode[] Page { get { return _page; } } - public int Index + public readonly int Index { get { return _idx; } } - public override int GetHashCode() + public override readonly int GetHashCode() { return XPathNodeHelper.GetLocation(_page, _idx); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEventCache.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEventCache.cs index 2f4394cfb2d5f..47466121e8f91 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEventCache.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEventCache.cs @@ -633,27 +633,27 @@ public void InitEvent(XmlEventType eventType, object? o) _o = o; } - public XmlEventType EventType + public readonly XmlEventType EventType { get { return _eventType; } } - public string? String1 + public readonly string? String1 { get { return _s1; } } - public string? String2 + public readonly string? String2 { get { return _s2; } } - public string? String3 + public readonly string? String3 { get { return _s3; } } - public object? Object + public readonly object? Object { get { return _o; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReader.cs index e27203cd84799..f3142fd50a1bb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlReader.cs @@ -1953,7 +1953,7 @@ internal XmlReaderDebuggerDisplayProxy(XmlReader reader) _reader = reader; } - public override string ToString() + public override readonly string ToString() { XmlNodeType nt = _reader.NodeType; string result = nt.ToString(); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs index c2feee7131890..0d27c704af0d1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplHelpers.cs @@ -99,7 +99,7 @@ internal void Close(bool closeInput) } } - internal int LineNo + internal readonly int LineNo { get { @@ -107,7 +107,7 @@ internal int LineNo } } - internal int LinePos + internal readonly int LinePos { get { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpers.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpers.cs index e905d9663c363..e7bd30f8e0226 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpers.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpers.cs @@ -57,12 +57,12 @@ internal void Set(string prefix, string localName, string namespaceUri, int prev this.xmlLang = null; } - internal void WriteEndElement(XmlRawWriter rawWriter) + internal readonly void WriteEndElement(XmlRawWriter rawWriter) { rawWriter.WriteEndElement(prefix, localName, namespaceUri); } - internal void WriteFullEndElement(XmlRawWriter rawWriter) + internal readonly void WriteFullEndElement(XmlRawWriter rawWriter) { rawWriter.WriteFullEndElement(prefix, localName, namespaceUri); } @@ -91,7 +91,7 @@ internal void Set(string prefix, string namespaceUri, NamespaceKind kind) this.prevNsIndex = -1; } - internal void WriteDecl(XmlWriter writer, XmlRawWriter? rawWriter) + internal readonly void WriteDecl(XmlWriter writer, XmlRawWriter? rawWriter) { Debug.Assert(kind == NamespaceKind.NeedToWrite); if (null != rawWriter) @@ -130,7 +130,7 @@ internal void Set(string prefix, string localName, string namespaceUri) this.prev = 0; } - internal bool IsDuplicate(string prefix, string localName, string namespaceUri) + internal readonly bool IsDuplicate(string prefix, string localName, string namespaceUri) { return ((this.localName == localName) && ((this.prefix == prefix) || (this.namespaceUri == namespaceUri))); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpersAsync.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpersAsync.cs index fb81eb472358c..b79593c1d3877 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpersAsync.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpersAsync.cs @@ -14,12 +14,12 @@ internal sealed partial class XmlWellFormedWriter : XmlWriter { private partial struct ElementScope { - internal Task WriteEndElementAsync(XmlRawWriter rawWriter) + internal readonly Task WriteEndElementAsync(XmlRawWriter rawWriter) { return rawWriter.WriteEndElementAsync(prefix, localName, namespaceUri); } - internal Task WriteFullEndElementAsync(XmlRawWriter rawWriter) + internal readonly Task WriteFullEndElementAsync(XmlRawWriter rawWriter) { return rawWriter.WriteFullEndElementAsync(prefix, localName, namespaceUri); } @@ -27,7 +27,7 @@ internal Task WriteFullEndElementAsync(XmlRawWriter rawWriter) private partial struct Namespace { - internal async Task WriteDeclAsync(XmlWriter writer, XmlRawWriter? rawWriter) + internal async readonly Task WriteDeclAsync(XmlWriter writer, XmlRawWriter? rawWriter) { Debug.Assert(kind == NamespaceKind.NeedToWrite); if (null != rawWriter) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNamedNodeMap.SmallXmlNodeList.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNamedNodeMap.SmallXmlNodeList.cs index 021941038895b..4cf8e032514bb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNamedNodeMap.SmallXmlNodeList.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNamedNodeMap.SmallXmlNodeList.cs @@ -19,7 +19,7 @@ internal struct SmallXmlNodeList // never degrades back, even if all elements are removed. private object? _field; - public int Count + public readonly int Count { get { @@ -34,7 +34,7 @@ public int Count } } - public object this[int index] + public readonly object this[int index] { get { @@ -181,7 +181,7 @@ public void Reset() } } - public IEnumerator GetEnumerator() + public readonly IEnumerator GetEnumerator() { if (_field == null) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs index 02b452c945d73..b7ddd38192ef2 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/FacetChecker.cs @@ -379,7 +379,7 @@ internal void FinishFacetCompile() } } - private void CheckValue(object value, XmlSchemaFacet facet) + private readonly void CheckValue(object value, XmlSchemaFacet facet) { RestrictionFacets? restriction = _datatype.Restriction; switch (facet.FacetType) @@ -669,7 +669,7 @@ private void CopyFacetsFromBaseType() } } - private object ParseFacetValue(XmlSchemaDatatype datatype, XmlSchemaFacet facet, string code, IXmlNamespaceResolver? nsmgr, XmlNameTable? nameTable) + private readonly object ParseFacetValue(XmlSchemaDatatype datatype, XmlSchemaFacet facet, string code, IXmlNamespaceResolver? nsmgr, XmlNameTable? nameTable) { object? typedValue; Exception? ex = datatype.TryParseValue(facet.Value!, nameTable, nsmgr, out typedValue); @@ -749,7 +749,7 @@ private static string Preprocess(string pattern) return bufBld.ToString(); } - private void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) + private readonly void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) { if ((_validRestrictionFlags & flag) == 0) { @@ -757,7 +757,7 @@ private void CheckProhibitedFlag(XmlSchemaFacet facet, RestrictionFlags flag, st } } - private void CheckDupFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) + private readonly void CheckDupFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) { if ((_derivedRestriction.Flags & flag) != 0) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs index 717bc204e5827..7b4d70273d788 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs @@ -247,7 +247,7 @@ public XsdDateTime(DateTimeOffset dateTimeOffset, XsdDateTimeFlags kinds) /// /// Returns auxiliary enumeration of XSD date type /// - private DateTimeTypeCode InternalTypeCode + private readonly DateTimeTypeCode InternalTypeCode { get { return (DateTimeTypeCode)((_extra & TypeMask) >> TypeShift); } } @@ -255,7 +255,7 @@ private DateTimeTypeCode InternalTypeCode /// /// Returns geographical "position" of the value /// - private XsdDateTimeKind InternalKind + private readonly XsdDateTimeKind InternalKind { get { return (XsdDateTimeKind)((_extra & KindMask) >> KindShift); } } @@ -263,7 +263,7 @@ private XsdDateTimeKind InternalKind /// /// Returns XmlTypeCode of the value being stored /// - public XmlTypeCode TypeCode + public readonly XmlTypeCode TypeCode { get { return s_typeCodes[(int)InternalTypeCode]; } } @@ -272,7 +272,7 @@ public XmlTypeCode TypeCode /// Returns the year part of XsdDateTime /// The returned value is integer between 1 and 9999 /// - public int Year + public readonly int Year { get { return _dt.Year; } } @@ -281,7 +281,7 @@ public int Year /// Returns the month part of XsdDateTime /// The returned value is integer between 1 and 12 /// - public int Month + public readonly int Month { get { return _dt.Month; } } @@ -290,7 +290,7 @@ public int Month /// Returns the day of the month part of XsdDateTime /// The returned value is integer between 1 and 31 /// - public int Day + public readonly int Day { get { return _dt.Day; } } @@ -299,7 +299,7 @@ public int Day /// Returns the hour part of XsdDateTime /// The returned value is integer between 0 and 23 /// - public int Hour + public readonly int Hour { get { return _dt.Hour; } } @@ -308,7 +308,7 @@ public int Hour /// Returns the minute part of XsdDateTime /// The returned value is integer between 0 and 60 /// - public int Minute + public readonly int Minute { get { return _dt.Minute; } } @@ -317,7 +317,7 @@ public int Minute /// Returns the second part of XsdDateTime /// The returned value is integer between 0 and 60 /// - public int Second + public readonly int Second { get { return _dt.Second; } } @@ -326,7 +326,7 @@ public int Second /// Returns number of ticks in the fraction of the second /// The returned value is integer between 0 and 9999999 /// - public int Fraction + public readonly int Fraction { get { return (int)(_dt.Ticks % ticksToFractionDivisor); } } @@ -335,7 +335,7 @@ public int Fraction /// Returns the hour part of the time zone /// The returned value is integer between -13 and 13 /// - public int ZoneHour + public readonly int ZoneHour { get { @@ -348,7 +348,7 @@ public int ZoneHour /// Returns the minute part of the time zone /// The returned value is integer between 0 and 60 /// - public int ZoneMinute + public readonly int ZoneMinute { get { @@ -574,7 +574,7 @@ private void PrintDate(StringBuilder sb) // day once. As we know that we need all 3 values, by duplicating the // logic here we can calculate the number of days and return the intermediate // calculations for month and year without the added cost. - private void GetYearMonthDay(out int year, out int month, out int day) + private readonly void GetYearMonthDay(out int year, out int month, out int day) { long ticks = _dt.Ticks; // n = number of days since 1/1/0001 @@ -1039,7 +1039,7 @@ private bool ParseZoneAndWhitespace(int start) } - private bool Parse4Dig(int start, ref int num) + private readonly bool Parse4Dig(int start, ref int num) { if (start + 3 < _length) { @@ -1060,7 +1060,7 @@ private bool Parse4Dig(int start, ref int num) return false; } - private bool Parse2Dig(int start, ref int num) + private readonly bool Parse2Dig(int start, ref int num) { if (start + 1 < _length) { @@ -1077,7 +1077,7 @@ private bool Parse2Dig(int start, ref int num) return false; } - private bool ParseChar(int start, char ch) + private readonly bool ParseChar(int start, char ch) { return start < _length && _text[start] == ch; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDuration.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDuration.cs index 454d7f8eb8359..dc1cc71263d1a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDuration.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDuration.cs @@ -166,7 +166,7 @@ public XsdDuration(string s, DurationType durationType) /// /// Return true if this duration is negative. /// - public bool IsNegative + public readonly bool IsNegative { get { return (_nanoseconds & NegativeBit) != 0; } } @@ -174,7 +174,7 @@ public bool IsNegative /// /// Return number of years in this duration (stored in 31 bits). /// - public int Years + public readonly int Years { get { return _years; } } @@ -182,7 +182,7 @@ public int Years /// /// Return number of months in this duration (stored in 31 bits). /// - public int Months + public readonly int Months { get { return _months; } } @@ -190,7 +190,7 @@ public int Months /// /// Return number of days in this duration (stored in 31 bits). /// - public int Days + public readonly int Days { get { return _days; } } @@ -198,7 +198,7 @@ public int Days /// /// Return number of hours in this duration (stored in 31 bits). /// - public int Hours + public readonly int Hours { get { return _hours; } } @@ -206,7 +206,7 @@ public int Hours /// /// Return number of minutes in this duration (stored in 31 bits). /// - public int Minutes + public readonly int Minutes { get { return _minutes; } } @@ -214,7 +214,7 @@ public int Minutes /// /// Return number of seconds in this duration (stored in 31 bits). /// - public int Seconds + public readonly int Seconds { get { return _seconds; } } @@ -222,7 +222,7 @@ public int Seconds /// /// Return number of nanoseconds in this duration. /// - public int Nanoseconds + public readonly int Nanoseconds { get { return (int)(_nanoseconds & ~NegativeBit); } } @@ -231,7 +231,7 @@ public int Nanoseconds /// Internal helper method that converts an Xsd duration to a TimeSpan value. This code uses the estimate /// that there are 365 days in the year and 30 days in a month. /// - public TimeSpan ToTimeSpan() + public readonly TimeSpan ToTimeSpan() { return ToTimeSpan(DurationType.Duration); } @@ -240,7 +240,7 @@ public TimeSpan ToTimeSpan() /// Internal helper method that converts an Xsd duration to a TimeSpan value. This code uses the estimate /// that there are 365 days in the year and 30 days in a month. /// - public TimeSpan ToTimeSpan(DurationType durationType) + public readonly TimeSpan ToTimeSpan(DurationType durationType) { TimeSpan result; Exception? exception = TryToTimeSpan(durationType, out result); @@ -252,12 +252,12 @@ public TimeSpan ToTimeSpan(DurationType durationType) return result; } - internal Exception? TryToTimeSpan(out TimeSpan result) + internal readonly Exception? TryToTimeSpan(out TimeSpan result) { return TryToTimeSpan(DurationType.Duration, out result); } - internal Exception? TryToTimeSpan(DurationType durationType, out TimeSpan result) + internal readonly Exception? TryToTimeSpan(DurationType durationType, out TimeSpan result) { Exception? exception = null; ulong ticks = 0; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs index 2e6ecc3d16d6d..1f940be07ec48 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs @@ -30,7 +30,7 @@ public struct XmlDeserializationEvents public XmlNodeEventHandler? OnUnknownNode { - get + readonly get { return _onUnknownNode; } @@ -43,7 +43,7 @@ public XmlNodeEventHandler? OnUnknownNode public XmlAttributeEventHandler? OnUnknownAttribute { - get + readonly get { return _onUnknownAttribute; } @@ -55,7 +55,7 @@ public XmlAttributeEventHandler? OnUnknownAttribute public XmlElementEventHandler? OnUnknownElement { - get + readonly get { return _onUnknownElement; } @@ -67,7 +67,7 @@ public XmlElementEventHandler? OnUnknownElement public UnreferencedObjectEventHandler? OnUnreferencedObject { - get + readonly get { return _onUnreferencedObject; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/LogicalExpr.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/LogicalExpr.cs index 1e1b0d95984eb..75dcf216b6557 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/LogicalExpr.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/LogicalExpr.cs @@ -431,7 +431,7 @@ public void Reset() _opnd.Reset(); } - public string Value { get { return _current!.Value; } } + public readonly string Value { get { return _current!.Value; } } } private static string Rtf(object o) { return ((XPathNavigator)o).Value; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathNavigator.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathNavigator.cs index 6568055ff2d6a..ade984c117057 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathNavigator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathNavigator.cs @@ -2222,7 +2222,7 @@ public DebuggerDisplayProxy(XPathNavigator nav) { _nav = nav; } - public override string ToString() + public override readonly string ToString() { string result = _nav.NodeType.ToString(); switch (_nav.NodeType) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs index cc7b1fcc8394c..cd5805ca1dde5 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs @@ -169,7 +169,7 @@ public StorageDescriptor ToStorageType(Type itemStorageType) /// /// Return an enumeration specifying where the value is located. /// - public ItemLocation Location + public readonly ItemLocation Location { get { return _location; } } @@ -177,7 +177,7 @@ public ItemLocation Location /// /// Return the index of the parameter that stores this iterator's values. /// - public int ParameterLocation + public readonly int ParameterLocation { get { return (int)_locationObject; } } @@ -185,7 +185,7 @@ public int ParameterLocation /// /// Return the LocalBuilder that stores this iterator's values. /// - public LocalBuilder? LocalLocation + public readonly LocalBuilder? LocalLocation { get { return _locationObject as LocalBuilder; } } @@ -194,7 +194,7 @@ public LocalBuilder? LocalLocation /// Return the "Current" location information (LocalBuilder and Current MethodInfo) that will store /// this iterator's helper class. The Current property on this iterator can be accessed to get the CurrentMethod. /// - public CurrentContext? CurrentLocation + public readonly CurrentContext? CurrentLocation { get { return _locationObject as CurrentContext; } } @@ -202,7 +202,7 @@ public CurrentContext? CurrentLocation /// /// Return the MethodInfo for the method that computes this global value. /// - public MethodInfo? GlobalLocation + public readonly MethodInfo? GlobalLocation { get { return _locationObject as MethodInfo; } } @@ -210,7 +210,7 @@ public MethodInfo? GlobalLocation /// /// Return true if this iterator's values are cached. /// - public bool IsCached + public readonly bool IsCached { get { return _isCached; } } @@ -218,7 +218,7 @@ public bool IsCached /// /// Return the Clr type of an individual item in the storage location (never an IList{T} type). /// - public Type ItemStorageType + public readonly Type ItemStorageType { get { return _itemStorageType; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ListBase.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ListBase.cs index d2996cf63f3df..8157ca66d4e74 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ListBase.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/ListBase.cs @@ -229,7 +229,7 @@ public void Dispose() /// /// Return current item. Return default value if before first item or after last item in the list. /// - public T Current + public readonly T Current { get { return _current; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs index 8e3e1a4b841a7..ecc53e7fbf0c6 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs @@ -18,10 +18,10 @@ public Int32Pair(int left, int right) _right = right; } - public int Left { get { return _left; } } - public int Right { get { return _right; } } + public readonly int Left { get { return _left; } } + public readonly int Right { get { return _right; } } - public override bool Equals([NotNullWhen(true)] object? other) + public override readonly bool Equals([NotNullWhen(true)] object? other) { if (other is Int32Pair) { @@ -32,7 +32,7 @@ public override bool Equals([NotNullWhen(true)] object? other) return false; } - public override int GetHashCode() + public override readonly int GetHashCode() { return _left.GetHashCode() ^ _right.GetHashCode(); } @@ -49,7 +49,7 @@ public StringPair(string left, string right) _right = right; } - public string Left { get { return _left; } } - public string Right { get { return _right; } } + public readonly string Left { get { return _left; } } + public readonly string Right { get { return _right; } } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/ContentIterators.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/ContentIterators.cs index 44ec8492d2224..f18380bb09088 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/ContentIterators.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/ContentIterators.cs @@ -47,7 +47,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -92,7 +92,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -137,7 +137,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -179,7 +179,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -232,7 +232,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -274,7 +274,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -423,7 +423,7 @@ internal IteratorResult MoveNext(XPathNavigator input, bool isContent) /// /// Return the current result navigator. This is only defined after MoveNext() has returned IteratorResult.HaveCurrentNode. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/SetIterators.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/SetIterators.cs index 7001187ecbc35..e5c951323132d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/SetIterators.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/SetIterators.cs @@ -129,7 +129,7 @@ public SetIteratorResult MoveNext(XPathNavigator nestedNavigator) /// /// Return the current result navigator. This is only defined after MoveNext() has returned -1. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurr; } } @@ -246,7 +246,7 @@ public SetIteratorResult MoveNext(XPathNavigator nestedNavigator) /// /// Return the current result navigator. This is only defined after MoveNext() has returned -1. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navLeft; } } @@ -349,7 +349,7 @@ public SetIteratorResult MoveNext(XPathNavigator nestedNavigator) /// /// Return the current result navigator. This is only defined after MoveNext() has returned -1. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navLeft; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/SiblingIterators.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/SiblingIterators.cs index 15eab78c27b96..bd02a5b7ce90d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/SiblingIterators.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/SiblingIterators.cs @@ -42,7 +42,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -80,7 +80,7 @@ public IteratorResult MoveNext(XPathNavigator navigator) /// /// Return the current result navigator. This is only defined after MoveNext() has returned IteratorResult.HaveCurrent. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _wrapped.Current; } } @@ -117,7 +117,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -193,7 +193,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/StringConcat.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/StringConcat.cs index f2f61ca05081e..2b7bc43599039 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/StringConcat.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/StringConcat.cs @@ -35,14 +35,14 @@ public void Clear() /// public string? Delimiter { - get { return _delimiter; } + readonly get { return _delimiter; } set { _delimiter = value; } } /// /// Return the number of concatenated strings, including delimiters. /// - internal int Count + internal readonly int Count { get { return _idxStr; } } @@ -66,7 +66,7 @@ public void Concat(string value) /// /// Get the result string. /// - public string GetResult() => + public readonly string GetResult() => _idxStr switch { 0 => string.Empty, diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/TreeIterators.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/TreeIterators.cs index 07a9798589437..ab28cf195b356 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/TreeIterators.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/TreeIterators.cs @@ -59,7 +59,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -136,7 +136,7 @@ public IteratorResult MoveNext(XPathNavigator input) /// /// Return the current result navigator. This is only defined after MoveNext() has returned true or IteratorResult.HaveCurrentNode. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -183,7 +183,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -241,7 +241,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -286,7 +286,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -337,7 +337,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -484,7 +484,7 @@ public IteratorResult MoveNext(XPathNavigator input) /// /// Return the current result navigator. This is only defined after MoveNext() has returned true or IteratorResult.HaveCurrentNode. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -579,7 +579,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -626,7 +626,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -685,7 +685,7 @@ public bool MoveNext() /// Return the current result navigator. This is only defined after MoveNext() has returned true or /// IteratorResult.HaveCurrentNode. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -821,7 +821,7 @@ public IteratorResult MoveNext(XPathNavigator input) /// Return the current result navigator. This is only defined after MoveNext() has returned true or /// IteratorResult.HaveCurrentNode. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } @@ -935,7 +935,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlAggregates.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlAggregates.cs index 65dabdf77e5ef..035d3255ce402 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlAggregates.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlAggregates.cs @@ -62,12 +62,12 @@ public void Maximum(int value) _cnt = 1; } - public int SumResult { get { return _result; } } - public int AverageResult { get { return _result / _cnt; } } - public int MinimumResult { get { return _result; } } - public int MaximumResult { get { return _result; } } + public readonly int SumResult { get { return _result; } } + public readonly int AverageResult { get { return _result / _cnt; } } + public readonly int MinimumResult { get { return _result; } } + public readonly int MaximumResult { get { return _result; } } - public bool IsEmpty { get { return _cnt == 0; } } + public readonly bool IsEmpty { get { return _cnt == 0; } } } @@ -124,12 +124,12 @@ public void Maximum(long value) _cnt = 1; } - public long SumResult { get { return _result; } } - public long AverageResult { get { return _result / (long)_cnt; } } - public long MinimumResult { get { return _result; } } - public long MaximumResult { get { return _result; } } + public readonly long SumResult { get { return _result; } } + public readonly long AverageResult { get { return _result / (long)_cnt; } } + public readonly long MinimumResult { get { return _result; } } + public readonly long MaximumResult { get { return _result; } } - public bool IsEmpty { get { return _cnt == 0; } } + public readonly bool IsEmpty { get { return _cnt == 0; } } } @@ -186,12 +186,12 @@ public void Maximum(decimal value) _cnt = 1; } - public decimal SumResult { get { return _result; } } - public decimal AverageResult { get { return _result / (decimal)_cnt; } } - public decimal MinimumResult { get { return _result; } } - public decimal MaximumResult { get { return _result; } } + public readonly decimal SumResult { get { return _result; } } + public readonly decimal AverageResult { get { return _result / (decimal)_cnt; } } + public readonly decimal MinimumResult { get { return _result; } } + public readonly decimal MaximumResult { get { return _result; } } - public bool IsEmpty { get { return _cnt == 0; } } + public readonly bool IsEmpty { get { return _cnt == 0; } } } @@ -248,11 +248,11 @@ public void Maximum(double value) _cnt = 1; } - public double SumResult { get { return _result; } } - public double AverageResult { get { return _result / (double)_cnt; } } - public double MinimumResult { get { return _result; } } - public double MaximumResult { get { return _result; } } + public readonly double SumResult { get { return _result; } } + public readonly double AverageResult { get { return _result / (double)_cnt; } } + public readonly double MinimumResult { get { return _result; } } + public readonly double MaximumResult { get { return _result; } } - public bool IsEmpty { get { return _cnt == 0; } } + public readonly bool IsEmpty { get { return _cnt == 0; } } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlAttributeCache.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlAttributeCache.cs index 0a4560db11d68..ec09ed97da450 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlAttributeCache.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlAttributeCache.cs @@ -276,12 +276,12 @@ private struct AttrNameVal private int _hashCode; private int _nextNameIndex; - public string LocalName { get { return _localName; } } - public string Prefix { get { return _prefix; } } - public string Namespace { get { return _namespaceName; } } - public string Text { get { return _text; } } - public XmlAtomicValue Value { get { return _value; } } - public int NextNameIndex { get { return _nextNameIndex; } set { _nextNameIndex = value; } } + public readonly string LocalName { get { return _localName; } } + public readonly string Prefix { get { return _prefix; } } + public readonly string Namespace { get { return _namespaceName; } } + public readonly string Text { get { return _text; } } + public readonly XmlAtomicValue Value { get { return _value; } } + public int NextNameIndex { readonly get { return _nextNameIndex; } set { _nextNameIndex = value; } } /// /// Cache an attribute's name and type. diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlCollation.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlCollation.cs index 224747d64468e..34ab402ecdeea 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlCollation.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlCollation.cs @@ -54,7 +54,7 @@ public Options(int value) _value = value; } - public bool GetFlag(int flag) + public readonly bool GetFlag(int flag) { return (_value & flag) != 0; } @@ -69,33 +69,33 @@ public void SetFlag(int flag, bool value) public bool UpperFirst { - get { return GetFlag(FlagUpperFirst); } + readonly get { return GetFlag(FlagUpperFirst); } set { SetFlag(FlagUpperFirst, value); } } - public bool EmptyGreatest + public readonly bool EmptyGreatest { get { return GetFlag(FlagEmptyGreatest); } } - public bool DescendingOrder + public readonly bool DescendingOrder { get { return GetFlag(FlagDescendingOrder); } } - public bool IgnoreCase + public readonly bool IgnoreCase { get { return GetFlag((int)CompareOptions.IgnoreCase); } } - public bool Ordinal + public readonly bool Ordinal { get { return GetFlag((int)CompareOptions.Ordinal); } } public CompareOptions CompareOptions { - get + readonly get { return (CompareOptions)(_value & ~Mask); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlIterators.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlIterators.cs index 4964e538b3c30..270e189d4b01f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlIterators.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlIterators.cs @@ -54,7 +54,7 @@ public bool MoveNext() /// /// Return the current result navigator. This is only defined after MoveNext() has returned true. /// - public XPathNavigator Current + public readonly XPathNavigator Current { get { return _navCurrent; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlNavigatorStack.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlNavigatorStack.cs index 08b530c4aba3c..33a7f038c60f1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlNavigatorStack.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlNavigatorStack.cs @@ -58,7 +58,7 @@ public XPathNavigator Pop() /// /// Returns the navigator at the top of the stack without adjusting the stack pointer /// - public XPathNavigator Peek() + public readonly XPathNavigator Peek() { Debug.Assert(!IsEmpty); return _stkNav[_sp - 1]; @@ -75,7 +75,7 @@ public void Reset() /// /// Returns true if there are no navigators in the stack /// - public bool IsEmpty + public readonly bool IsEmpty { get { return _sp == 0; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlSortKeyAccumulator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlSortKeyAccumulator.cs index 29fc8c76b2dff..7c6a95fe23b4a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlSortKeyAccumulator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlSortKeyAccumulator.cs @@ -106,7 +106,7 @@ private void AppendSortKey(XmlSortKey key) /// /// Get array of sort keys that was constructed by this internal class. /// - public Array Keys + public readonly Array Keys { get { return _keys; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs index ac4e94d9bc5f7..230015f2280d1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs @@ -10,15 +10,15 @@ internal struct Location { private readonly ulong _value; - public int Line { get { return (int)(_value >> 32); } } - public int Pos { get { return unchecked((int)(_value)); } } + public readonly int Line { get { return (int)(_value >> 32); } } + public readonly int Pos { get { return unchecked((int)(_value)); } } public Location(int line, int pos) { _value = (((ulong)line) << 32) | (uint)pos; } - public bool LessOrEqual(Location that) + public readonly bool LessOrEqual(Location that) { return _value <= that._value; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPathConvert.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPathConvert.cs index ed6d5cc482e4e..c5217874bae3f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPathConvert.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPathConvert.cs @@ -205,7 +205,7 @@ private struct BigNumber // one bit before the least significant bit of u0. private uint _error; - public uint Error { get { return _error; } } + public readonly uint Error { get { return _error; } } public BigNumber(uint u0, uint u1, uint u2, int exp, uint error) { @@ -382,7 +382,7 @@ private void Round(uint uExtra) #endif // Test to see if the num is zero. This works even if we're not normalized. - private bool IsZero + private readonly bool IsZero { get { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs index 1046765a2d3b2..d862a1bbb1fb1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs @@ -96,7 +96,7 @@ public static XmlQueryCardinality ZeroOrMore /// /// Strongly-typed Equals that returns true if this type and "other" type are equivalent. /// - public bool Equals(XmlQueryCardinality other) + public readonly bool Equals(XmlQueryCardinality other) { return _value == other._value; } @@ -120,7 +120,7 @@ public bool Equals(XmlQueryCardinality other) /// /// True if "other" is an XmlQueryCardinality, and this type is the exact same static type. /// - public override bool Equals([NotNullWhen(true)] object? other) + public override readonly bool Equals([NotNullWhen(true)] object? other) { if (other is XmlQueryCardinality) { @@ -133,7 +133,7 @@ public override bool Equals([NotNullWhen(true)] object? other) /// /// Return hash code of this instance. /// - public override int GetHashCode() + public override readonly int GetHashCode() { return _value; } @@ -193,7 +193,7 @@ private bool IsSubset(XmlQueryCardinality other) { /// Compute the cardinality of a subset of a set of the given cardinality. /// /// the cardinality of a subset - public XmlQueryCardinality AtMost() + public readonly XmlQueryCardinality AtMost() { // Fill downward to zero return new XmlQueryCardinality(_value | (_value >> 1) | (_value >> 2)); @@ -206,7 +206,7 @@ public XmlQueryCardinality AtMost() /// None op ~None = false /// ~None op None = true /// - public bool NeverSubset(XmlQueryCardinality other) + public readonly bool NeverSubset(XmlQueryCardinality other) { return _value != 0 && (_value & other._value) == 0; } @@ -274,7 +274,7 @@ public bool NeverSubset(XmlQueryCardinality other) /// /// Return the string representation of a cardinality, normalized to either ?, +, *, or "" (card 1). /// - public string ToString(string format) + public readonly string ToString(string format) { if (format == "S") { @@ -289,7 +289,7 @@ public string ToString(string format) /// /// Return the string representation of a cardinality, normalized to either ?, +, *, or "" (card 1). /// - public override string ToString() + public override readonly string ToString() { return s_toString[_value]; } @@ -297,7 +297,7 @@ public override string ToString() /// /// Serialize the object to BinaryWriter. /// - public void GetObjectData(BinaryWriter writer) + public readonly void GetObjectData(BinaryWriter writer) { writer.Write((byte)_value); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs index e3e8331c6e127..12c2d719f5793 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs @@ -38,8 +38,8 @@ public struct ScopeRecord public V value; // value for variable, null for namespace // Exactly one of these three properties is true for every given record - public bool IsVariable { get { return (flags & ScopeFlags.Variable) != 0; } } - public bool IsNamespace { get { return (flags & ScopeFlags.NsDecl) != 0; } } + public readonly bool IsVariable { get { return (flags & ScopeFlags.Variable) != 0; } } + public readonly bool IsNamespace { get { return (flags & ScopeFlags.NsDecl) != 0; } } // public bool IsExNamespace { get { return (flags & ScopeFlags.NsExcl ) != 0; } } } @@ -407,7 +407,7 @@ public bool MoveNext() return false; } - public ScopeRecord Current + public readonly ScopeRecord Current { get { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Focus.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Focus.cs index cce691ba93b54..05c9c2b0621bc 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Focus.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Focus.cs @@ -64,12 +64,12 @@ public void SetFocus(QilIterator? current) } [Conditional("DEBUG")] - private void CheckFocus() + private readonly void CheckFocus() { Debug.Assert(_focusType != SingletonFocusType.None, "Focus is not set, call SetFocus first"); } - public QilNode GetCurrent() + public readonly QilNode GetCurrent() { CheckFocus(); switch (_focusType) @@ -82,13 +82,13 @@ public QilNode GetCurrent() } } - public QilNode GetPosition() + public readonly QilNode GetPosition() { CheckFocus(); return _f.Double(1); } - public QilNode GetLast() + public readonly QilNode GetLast() { CheckFocus(); return _f.Double(1); @@ -127,24 +127,24 @@ public void StopFocus() _isSet = false; _current = _position = _last = null; } - public bool IsFocusSet + public readonly bool IsFocusSet { get { return _isSet; } } - public QilNode GetCurrent() + public readonly QilNode GetCurrent() { Debug.Assert(_current != null, "Naked current() is not expected in this function"); return _current; } - public QilNode GetPosition() + public readonly QilNode GetPosition() { Debug.Assert(_position != null, "Naked position() is not expected in this function"); return _position; } - public QilNode GetLast() + public readonly QilNode GetLast() { Debug.Assert(_last != null, "Naked last() is not expected in this function"); return _last; @@ -168,17 +168,17 @@ public void SetFocus(QilIterator current) _cached = _last = null; } - public bool IsFocusSet + public readonly bool IsFocusSet { get { return _current != null; } } - public QilNode? GetCurrent() + public readonly QilNode? GetCurrent() { return _current; } - public QilNode GetPosition() + public readonly QilNode GetPosition() { return _f.XsltConvert(_f.PositionOf(_current!), T.DoubleX); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs index 482b951312942..a846bf4845c47 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs @@ -135,7 +135,7 @@ public ModeName(QilName mode, QilName name) this.Name = name; } - public override int GetHashCode() + public override readonly int GetHashCode() { return Mode.GetHashCode() ^ Name.GetHashCode(); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltInput.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltInput.cs index f203642824f61..1a481a5f2d8bb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltInput.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltInput.cs @@ -1212,7 +1212,7 @@ internal struct Record public Location start; public Location valueStart; public Location end; - public string QualifiedName { get { return prefix.Length == 0 ? localName : string.Concat(prefix, ":", localName); } } + public readonly string QualifiedName { get { return prefix.Length == 0 ? localName : string.Concat(prefix, ":", localName); } } } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/RootAction.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/RootAction.cs index 718a6be718ca5..dc493d0cce502 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/RootAction.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/RootAction.cs @@ -74,8 +74,8 @@ public DocumentKeyList(XPathNavigator rootNav, Hashtable keyTable) _keyTable = keyTable; } - public XPathNavigator RootNav { get { return _rootNav; } } - public Hashtable KeyTable { get { return _keyTable; } } + public readonly XPathNavigator RootNav { get { return _rootNav; } } + public readonly Hashtable KeyTable { get { return _keyTable; } } } internal class RootAction : TemplateBaseAction From a1ae378ee9a49bb4fc2771b7eba5059b9eadd9e9 Mon Sep 17 00:00:00 2001 From: hrrrrustic Date: Mon, 12 Apr 2021 14:15:27 +0300 Subject: [PATCH 2/3] readonly annotation .Linq --- .../System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs index 84f4af1d57b76..d9fe1250cabc8 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs @@ -292,7 +292,7 @@ public async Task WriteElementAsync(XElement e, CancellationToken cancellationTo } } - private string? GetPrefixOfNamespace(XNamespace ns, bool allowDefaultNamespace) + private readonly string? GetPrefixOfNamespace(XNamespace ns, bool allowDefaultNamespace) { string namespaceName = ns.NamespaceName; if (namespaceName.Length == 0) return string.Empty; @@ -556,7 +556,7 @@ private void FlushElement() } } - private string? GetPrefixOfNamespace(XNamespace ns, bool allowDefaultNamespace) + private readonly string? GetPrefixOfNamespace(XNamespace ns, bool allowDefaultNamespace) { string namespaceName = ns.NamespaceName; if (namespaceName.Length == 0) return string.Empty; From 3e85b43c8408fbf8842f904a4e5e028b54a2db03 Mon Sep 17 00:00:00 2001 From: hrrrrustic Date: Mon, 12 Apr 2021 15:26:25 +0300 Subject: [PATCH 3/3] ref file --- .../ref/System.Xml.XmlSerializer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Xml.XmlSerializer/ref/System.Xml.XmlSerializer.cs b/src/libraries/System.Xml.XmlSerializer/ref/System.Xml.XmlSerializer.cs index cfe776222b80f..699affa687402 100644 --- a/src/libraries/System.Xml.XmlSerializer/ref/System.Xml.XmlSerializer.cs +++ b/src/libraries/System.Xml.XmlSerializer/ref/System.Xml.XmlSerializer.cs @@ -270,10 +270,10 @@ public partial struct XmlDeserializationEvents { private object _dummy; private int _dummyPrimitive; - public System.Xml.Serialization.XmlAttributeEventHandler? OnUnknownAttribute { get { throw null; } set { } } - public System.Xml.Serialization.XmlElementEventHandler? OnUnknownElement { get { throw null; } set { } } - public System.Xml.Serialization.XmlNodeEventHandler? OnUnknownNode { get { throw null; } set { } } - public System.Xml.Serialization.UnreferencedObjectEventHandler? OnUnreferencedObject { get { throw null; } set { } } + public System.Xml.Serialization.XmlAttributeEventHandler? OnUnknownAttribute { readonly get { throw null; } set { } } + public System.Xml.Serialization.XmlElementEventHandler? OnUnknownElement { readonly get { throw null; } set { } } + public System.Xml.Serialization.XmlNodeEventHandler? OnUnknownNode { readonly get { throw null; } set { } } + public System.Xml.Serialization.UnreferencedObjectEventHandler? OnUnreferencedObject { readonly get { throw null; } set { } } } public partial class XmlElementAttributes : System.Collections.CollectionBase {