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 f2c53a5ca2209c..a43399d28bd6bb 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 @@ -120,7 +120,7 @@ public override string ToString() if (prefix.Length == 0) return this.localname; else - return this.prefix + ":" + this.localname; + return $"{this.prefix}:{this.localname}"; } public static bool operator ==(QName a, QName b) @@ -4048,7 +4048,7 @@ private string ValueAsString(BinXmlToken token) if (qname.prefix.Length == 0) return qname.localname; else - return string.Concat(qname.prefix, ":", qname.localname); + return $"{qname.prefix}:{qname.localname}"; } default: @@ -4422,7 +4422,7 @@ private object ValueAs(BinXmlToken token, Type returnType, IXmlNamespaceResolver private Exception ThrowUnexpectedToken(BinXmlToken token) { - System.Diagnostics.Debug.WriteLine("Unhandled token: " + token.ToString()); + System.Diagnostics.Debug.WriteLine($"Unhandled token: {token}"); return ThrowXmlException(SR.XmlBinary_UnexpectedToken); } 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 a2ab5b21217fe7..30480dabec290b 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 @@ -97,7 +97,7 @@ public string Name } else { - return string.Concat(Prefix, ":", LocalName); + return $"{Prefix}:{LocalName}"; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/QueryOutputWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/QueryOutputWriter.cs index 48f952a9e513f6..af14085e42a762 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/QueryOutputWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/QueryOutputWriter.cs @@ -163,7 +163,7 @@ public override void WriteStartElement(string? prefix, string localName, string? if (_outputDocType) { _wrapped.WriteDocType( - string.IsNullOrEmpty(prefix) ? localName : prefix + ":" + localName, + string.IsNullOrEmpty(prefix) ? localName : $"{prefix}:{localName}", _publicId, _systemId, null); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/QueryOutputWriterV1.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/QueryOutputWriterV1.cs index 02288d196166e0..e2ea18ca0fd9a7 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/QueryOutputWriterV1.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/QueryOutputWriterV1.cs @@ -145,7 +145,7 @@ public override void WriteStartElement(string? prefix, string localName, string? if (ws == WriteState.Start || ws == WriteState.Prolog) { _wrapped.WriteDocType( - string.IsNullOrEmpty(prefix) ? localName : prefix + ":" + localName, + string.IsNullOrEmpty(prefix) ? localName : $"{prefix}:{localName}", _publicId, _systemId, null); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/ValidatingReaderNodeData.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/ValidatingReaderNodeData.cs index f6fef4cb4beb68..127710f9754d05 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/ValidatingReaderNodeData.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/ValidatingReaderNodeData.cs @@ -84,7 +84,7 @@ public string GetAtomizedNameWPrefix(XmlNameTable nameTable) } else { - _nameWPrefix = nameTable.Add(string.Concat(_prefix, ":", _localName)); + _nameWPrefix = nameTable.Add($"{_prefix}:{_localName}"); } } 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 2f4394cfb2d5f3..4d51b5af35b663 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 @@ -242,7 +242,7 @@ public void EventsToWriter(XmlWriter writer) break; default: - Debug.Fail("Unknown event: " + page[idxEvent].EventType); + Debug.Fail($"Unknown event: {page[idxEvent].EventType}"); break; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs index 8d9718c6987164..0f5850fe6db2de 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlSubtreeReader.cs @@ -1326,7 +1326,7 @@ private void AddNamespace(string prefix, string ns) { localName = prefix; attrPrefix = _xmlns; - name = reader.NameTable.Add(string.Concat(_xmlns, ":", prefix)); + name = reader.NameTable.Add($"{_xmlns}:{prefix}"); } if (_nsAttributes[index] == null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs index d8e0f167f8970a..e2488431452082 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs @@ -555,7 +555,7 @@ internal XmlTextReaderImpl(string xmlFragment, XmlNodeType fragType, XmlParserCo internal XmlTextReaderImpl(string xmlFragment, XmlParserContext? context) : this(null == context || null == context.NameTable ? new NameTable() : context.NameTable) { - InitStringInput((context == null) ? string.Empty : context.BaseURI, Encoding.Unicode, string.Concat("")); + InitStringInput((context == null) ? string.Empty : context.BaseURI, Encoding.Unicode, $""); InitFragmentReader(XmlNodeType.XmlDeclaration, context, true); } 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 c2feee71318909..fa09441641ca45 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 @@ -681,7 +681,7 @@ internal string CreateNameWPrefix(XmlNameTable nt) } else { - nameWPrefix = nt.Add(string.Concat(prefix, ":", localName)); + nameWPrefix = nt.Add($"{prefix}:{localName}"); } return nameWPrefix; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs index c39f6155d3df36..731b661d70eebd 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs @@ -450,15 +450,15 @@ public override void WriteDocType(string name, string? pubid, string? sysid, str _textWriter.Write(name); if (pubid != null) { - _textWriter.Write(" PUBLIC " + _quoteChar); + _textWriter.Write($" PUBLIC {_quoteChar}"); _textWriter.Write(pubid); - _textWriter.Write(_quoteChar + " " + _quoteChar); + _textWriter.Write($"{_quoteChar} {_quoteChar}"); _textWriter.Write(sysid); _textWriter.Write(_quoteChar); } else if (sysid != null) { - _textWriter.Write(" SYSTEM " + _quoteChar); + _textWriter.Write($" SYSTEM {_quoteChar}"); _textWriter.Write(sysid); _textWriter.Write(_quoteChar); } @@ -1592,8 +1592,7 @@ private void PopNamespaces(int indexFrom, int indexTo) private string GeneratePrefix() { int temp = _stack[_top].prefixCount++ + 1; - return "d" + _top.ToString("d", CultureInfo.InvariantCulture) - + "p" + temp.ToString("d", CultureInfo.InvariantCulture); + return string.Create(CultureInfo.InvariantCulture, $"d{_top:d}p{temp:d}"); } private void InternalWriteProcessingInstruction(string name, string? text) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs index 583bd82b6e07f9..f4cb8945acce1f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs @@ -2074,7 +2074,7 @@ private static string GetStateName(State state) { if (state >= State.Error) { - Debug.Fail("We should never get to this point. State = " + state); + Debug.Fail($"We should never get to this point. State = {state}"); return "Error"; } else @@ -2176,7 +2176,7 @@ private void ThrowInvalidStateTransition(Token token, State currentState) case State.Start: if (_conformanceLevel == ConformanceLevel.Document) { - throw new InvalidOperationException(wrongTokenMessage + ' ' + SR.Xml_ConformanceLevelFragment); + throw new InvalidOperationException($"{wrongTokenMessage} {SR.Xml_ConformanceLevelFragment}"); } break; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReader.cs index a42e0fef36c26e..62e9a433a199c8 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XsdValidatingReader.cs @@ -244,7 +244,7 @@ public override string Name string? prefix = _validator.GetDefaultAttributePrefix(_cachedNode.Namespace); if (prefix != null && prefix.Length != 0) { - return prefix + ":" + _cachedNode.LocalName; + return $"{prefix}:{_cachedNode.LocalName}"; } return _cachedNode.LocalName; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/DocumentXmlWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/DocumentXmlWriter.cs index 3bcd7a3e0069b5..0f124f559320d9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/DocumentXmlWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/DocumentXmlWriter.cs @@ -441,7 +441,7 @@ private void CloseWithAppendAttribute() if (offset != -1 && ((XmlAttribute)attrs.nodes[offset]).Specified) { - throw new XmlException(SR.Xml_DupAttributeName, attr.Prefix.Length == 0 ? attr.LocalName : string.Concat(attr.Prefix, ":", attr.LocalName)); + throw new XmlException(SR.Xml_DupAttributeName, attr.Prefix.Length == 0 ? attr.LocalName : $"{attr.Prefix}:{attr.LocalName}"); } } for (int i = 0; i < _fragment.Count; i++) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlEntityReference.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlEntityReference.cs index 150e85f165903f..7a00a61bee947e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlEntityReference.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlEntityReference.cs @@ -188,7 +188,7 @@ private string ConstructBaseURI(string baseURI, string systemId) if (nCount > 0 && nCount < baseURI.Length) buf = baseURI.Substring(0, nCount); else if (nCount == 0) - buf = buf + "\\"; + buf = $"{buf}\\"; return (buf + systemId.Replace('\\', '/')); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlLoader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlLoader.cs index bb9ad265843a38..d4847fbe6ddb7b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlLoader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlLoader.cs @@ -865,7 +865,7 @@ private void RemoveDuplicateNamespace(XmlElement elem, XmlNamespaceManager mgr, private string EntitizeName(string name) { - return "&" + name + ";"; + return $"&{name};"; } //The function is called when expanding the entity when its children being asked diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlName.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlName.cs index 0cd270a420d8d2..b5d7939353b4c1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlName.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlName.cs @@ -91,7 +91,7 @@ public string Name { if (_localName.Length > 0) { - string n = string.Concat(_prefix, ":", _localName); + string n = $"{_prefix}:{_localName}"; lock (ownerDoc.NameTable) { if (_name == null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNode.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNode.cs index 8ac69732b433de..ce5118c2b0b656 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNode.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNode.cs @@ -1471,11 +1471,11 @@ public override string ToString() { case XmlNodeType.Element: case XmlNodeType.EntityReference: - result += ", Name=\"" + _node.Name + "\""; + result += $", Name=\"{_node.Name}\""; break; case XmlNodeType.Attribute: case XmlNodeType.ProcessingInstruction: - result += ", Name=\"" + _node.Name + "\", Value=\"" + XmlConvert.EscapeValueForDebuggerDisplay(_node.Value!) + "\""; + result += $", Name=\"{_node.Name}\", Value=\"{XmlConvert.EscapeValueForDebuggerDisplay(_node.Value!)}\""; break; case XmlNodeType.Text: case XmlNodeType.CDATA: @@ -1483,11 +1483,11 @@ public override string ToString() case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: case XmlNodeType.XmlDeclaration: - result += ", Value=\"" + XmlConvert.EscapeValueForDebuggerDisplay(_node.Value!) + "\""; + result += $", Value=\"{XmlConvert.EscapeValueForDebuggerDisplay(_node.Value!)}\""; break; case XmlNodeType.DocumentType: XmlDocumentType documentType = (XmlDocumentType)_node; - result += ", Name=\"" + documentType.Name + "\", SYSTEM=\"" + documentType.SystemId + "\", PUBLIC=\"" + documentType.PublicId + "\", Value=\"" + XmlConvert.EscapeValueForDebuggerDisplay(documentType.InternalSubset!) + "\""; + result += $", Name=\"{documentType.Name}\", SYSTEM=\"{documentType.SystemId}\", PUBLIC=\"{documentType.PublicId}\", Value=\"{XmlConvert.EscapeValueForDebuggerDisplay(documentType.InternalSubset!)}\""; break; default: break; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNodeReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNodeReader.cs index bfba0b21748c8f..6e3387dc072c31 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNodeReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlNodeReader.cs @@ -247,7 +247,7 @@ public string Value InitDecAttr(); for (int i = 0; i < _nDeclarationAttrCount; i++) { - strb.Append(decNodeAttributes[i].name + "=\"" + decNodeAttributes[i].value + "\""); + strb.Append($"{decNodeAttributes[i].name}=\"{decNodeAttributes[i].value}\""); if (i != (_nDeclarationAttrCount - 1)) strb.Append(' '); } @@ -859,7 +859,7 @@ public bool MoveToElement() if (prefix.Length == 0) attrName = "xmlns"; else - attrName = "xmlns:" + prefix; + attrName = $"xmlns:{prefix}"; // walk up the XmlNode parent chain, looking for the xmlns attribute XmlNode? node = _curNode; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs index fc5cafd2279426..fcc8d4b743cb0f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs @@ -233,7 +233,7 @@ public string NameOf(int symbol) { if ((int)de!.Value! == symbol) { - return (string)de.Key + ":*"; + return $"{(string)de.Key}:*"; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XdrBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XdrBuilder.cs index 113692da560233..dba37fa2395d20 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XdrBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XdrBuilder.cs @@ -653,7 +653,7 @@ private static void XDR_BeginRoot(XdrBuilder builder) { // inline xdr schema if (builder._XdrName != null) { - builder._TargetNamespace = builder._NameTable.Add("x-schema:#" + builder._XdrName); + builder._TargetNamespace = builder._NameTable.Add($"x-schema:#{builder._XdrName}"); } else { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaAny.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaAny.cs index dee86d0ee407e5..053a5c2dc8f384 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaAny.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaAny.cs @@ -69,7 +69,7 @@ internal override string NameString int i = 1; foreach (string wildcardNS in _namespaceList.Enumerate) { - sb.Append(wildcardNS + ":*"); + sb.Append($"{wildcardNS}:*"); if (i < _namespaceList.Enumerate.Count) { sb.Append(' '); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaDataType.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaDataType.cs index 31fb39ed805e24..fc4806a095920d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaDataType.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaDataType.cs @@ -106,7 +106,7 @@ internal string TypeCodeString } else { - typeCodeString = "List of " + TypeCodeToString(typeCode); + typeCodeString = $"List of {TypeCodeToString(typeCode)}"; } break; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaException.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaException.cs index eb6e6dd8c555cf..a31ca1f82c63c8 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaException.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaException.cs @@ -145,7 +145,7 @@ internal XmlSchemaException(string? res, string?[]? args, Exception? innerExcept } catch (MissingManifestResourceException) { - return "UNKNOWN(" + res + ")"; + return $"UNKNOWN({res})"; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaValidator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaValidator.cs index 0ca348043a0f8a..86b9f540552276 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaValidator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaValidator.cs @@ -2304,7 +2304,7 @@ private void ElementIdentityConstraints() { // selector selects new node, activate a new set of fields Debug.WriteLine("Selector Match!"); - Debug.WriteLine("Name: " + localName + "\t|\tURI: " + namespaceUri + "\n"); + Debug.WriteLine($"Name: {localName}\t|\tURI: {namespaceUri}\n"); // in which axisFields got updated constraintStructures[j].axisSelector.PushKS(_positionInfo.LineNumber, _positionInfo.LinePosition); @@ -2366,7 +2366,7 @@ private void AttributeIdentityConstraints(string name, string? ns, object obj, s //attribute is only simpletype, so needn't checking... // can fill value here, yeah!! Debug.WriteLine("Attribute Field Filling Value!"); - Debug.WriteLine("Name: " + name + "\t|\tURI: " + ns + "\t|\tValue: " + obj + "\n"); + Debug.WriteLine($"Name: {name}\t|\tURI: {ns}\t|\tValue: {obj}\n"); if (laxis.Ks[laxis.Column] != null) { // should be evaluated to either an empty node-set or a node-set with exactly one member @@ -2411,7 +2411,7 @@ private void EndElementIdentityConstraints(object typedValue, string stringValue if (laxis.isMatched) { Debug.WriteLine("Element Field Filling Value!"); - Debug.WriteLine("Name: " + localName + "\t|\tURI: " + namespaceUri + "\t|\tValue: " + typedValue + "\n"); + Debug.WriteLine($"Name: {localName}\t|\tURI: {namespaceUri}\t|\tValue: {typedValue}\n"); // fill value laxis.isMatched = false; if (laxis.Ks[laxis.Column] != null) @@ -2821,7 +2821,7 @@ private static void EnumerateAny(StringBuilder builder, string namespaces) internal static string QNameString(string localName, string ns) { - return (ns.Length != 0) ? string.Concat(ns, ":", localName) : localName; + return (ns.Length != 0) ? $"{ns}:{localName}" : localName; } internal static string BuildElementName(XmlQualifiedName qname) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlValueConverter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlValueConverter.cs index ff507ae1ab2938..3dd143e7b24dd0 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlValueConverter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlValueConverter.cs @@ -264,7 +264,7 @@ protected XmlBaseConverter(XmlTypeCode typeCode) break; default: - Debug.Fail("Type code " + typeCode + " is not supported."); + Debug.Fail($"Type code {typeCode} is not supported."); break; } @@ -475,15 +475,15 @@ protected static string QNameToString(XmlQualifiedName name) } else if (name.Namespace == XmlReservedNs.NsXs) { - return "xs:" + name.Name; + return $"xs:{name.Name}"; } else if (name.Namespace == XmlReservedNs.NsXQueryDataType) { - return "xdt:" + name.Name; + return $"xdt:{name.Name}"; } else { - return "{" + name.Namespace + "}" + name.Name; + return $"{{{name.Namespace}}}{name.Name}"; } } @@ -745,13 +745,13 @@ protected static string QNameToString(XmlQualifiedName qname, IXmlNamespaceResol string? prefix; if (nsResolver == null) - return string.Concat("{", qname.Namespace, "}", qname.Name); + return $"{{{qname.Namespace}}}{qname.Name}"; prefix = nsResolver.LookupPrefix(qname.Namespace); if (prefix == null) throw new InvalidCastException(SR.Format(SR.XmlConvert_TypeNoPrefix, qname, qname.Namespace)); - return (prefix.Length != 0) ? string.Concat(prefix, ":", qname.Name) : qname.Name; + return (prefix.Length != 0) ? $"{prefix}:{qname.Name}" : qname.Name; } protected static string TimeToString(DateTime value) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdBuilder.cs index 7a72a77d2a39ed..6eb97a7f94d77b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdBuilder.cs @@ -970,7 +970,7 @@ private XmlSchemaObject GetContainer(State state) container = _redefine!; break; default: - Debug.Fail("State is " + state); + Debug.Fail($"State is {state}"); break; } return container; @@ -1095,7 +1095,7 @@ private void SetContainer(State state, object container) _redefine = (XmlSchemaRedefine)container; break; default: - Debug.Fail("State is " + state); + Debug.Fail($"State is {state}"); break; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdValidator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdValidator.cs index ed95d6647417ab..f34d3b5e3c43d1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdValidator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdValidator.cs @@ -933,7 +933,7 @@ private void ElementIdentityConstraints() { // selector selects new node, activate a new set of fields Debug.WriteLine("Selector Match!"); - Debug.WriteLine("Name: " + reader.LocalName + "\t|\tURI: " + reader.NamespaceURI + "\n"); + Debug.WriteLine($"Name: {reader.LocalName}\t|\tURI: {reader.NamespaceURI}\n"); // in which axisFields got updated constraints[j].axisSelector.PushKS(PositionInfo.LineNumber, PositionInfo.LinePosition); } @@ -995,7 +995,7 @@ private void AttributeIdentityConstraints(string name, string ns, object? obj, s //attribute is only simpletype, so needn't checking... // can fill value here, yeah!! Debug.WriteLine("Attribute Field Filling Value!"); - Debug.WriteLine("Name: " + name + "\t|\tURI: " + ns + "\t|\tValue: " + obj + "\n"); + Debug.WriteLine($"Name: {name}\t|\tURI: {ns}\t|\tValue: {obj}\n"); if (laxis.Ks[laxis.Column] != null) { // should be evaluated to either an empty node-set or a node-set with exactly one member @@ -1047,7 +1047,7 @@ private void EndElementIdentityConstraints() if (laxis.isMatched) { Debug.WriteLine("Element Field Filling Value!"); - Debug.WriteLine("Name: " + reader.LocalName + "\t|\tURI: " + reader.NamespaceURI + "\t|\tValue: " + reader.TypedValueObject + "\n"); + Debug.WriteLine($"Name: {reader.LocalName}\t|\tURI: {reader.NamespaceURI}\t|\tValue: {reader.TypedValueObject}\n"); // fill value laxis.isMatched = false; if (laxis.Ks[laxis.Column] != null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs index d642fa0c98f554..eb098c59450f74 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/CodeGenerator.cs @@ -161,7 +161,7 @@ internal LocalBuilder GetTempLocal(Type type) LocalBuilder? localTmp; if (!_tmpLocals.TryGetValue(type, out localTmp)) { - localTmp = DeclareLocal(type, "_tmp" + _tmpLocals.Count); + localTmp = DeclareLocal(type, $"_tmp{_tmpLocals.Count}"); _tmpLocals.Add(type, localTmp); } return localTmp; @@ -1270,7 +1270,7 @@ internal static TypeBuilder CreateTypeBuilder( Type[] interfaces) { // parent is nullable if no base class - return moduleBuilder.DefineType(TempAssembly.GeneratedAssemblyNamespace + "." + name, + return moduleBuilder.DefineType($"{TempAssembly.GeneratedAssemblyNamespace}.{name}", attributes, parent, interfaces); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs index c3df77a5a2bc3f..6dffc8c2176090 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs @@ -244,17 +244,17 @@ internal void InitAssemblyMethods(XmlMapping[] xmlMappings) { if (!string.IsNullOrEmpty(type.Assembly.Location)) { - path = Path.Combine(Path.GetDirectoryName(type.Assembly.Location)!, assemblyName + ".dll"); + path = Path.Combine(Path.GetDirectoryName(type.Assembly.Location)!, $"{assemblyName}.dll"); } if ((string.IsNullOrEmpty(path) || !File.Exists(path)) && !string.IsNullOrEmpty(Assembly.GetEntryAssembly()?.Location)) { - path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!, assemblyName + ".dll"); + path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!, $"{assemblyName}.dll"); } if ((string.IsNullOrEmpty(path) || !File.Exists(path)) && !string.IsNullOrEmpty(AppContext.BaseDirectory)) { - path = Path.Combine(Path.GetDirectoryName(AppContext.BaseDirectory)!, assemblyName + ".dll"); + path = Path.Combine(Path.GetDirectoryName(AppContext.BaseDirectory)!, $"{assemblyName}.dll"); } if (!string.IsNullOrEmpty(path)) @@ -397,11 +397,11 @@ internal static bool GenerateSerializerToStream(XmlMapping[] xmlMappings, Type?[ } } - writer.WriteLine("namespace " + GeneratedAssemblyNamespace + " {"); + writer.WriteLine($"namespace {GeneratedAssemblyNamespace} {{"); writer.Indent++; writer.WriteLine(); - string writerClass = "XmlSerializationWriter" + suffix; + string writerClass = $"XmlSerializationWriter{suffix}"; writerClass = classes.AddUnique(writerClass, writerClass); var writerCodeGen = new XmlSerializationWriterCodeGen(writer, scopes, "public", writerClass); writerCodeGen.GenerateBegin(); @@ -415,7 +415,7 @@ internal static bool GenerateSerializerToStream(XmlMapping[] xmlMappings, Type?[ writerCodeGen.GenerateEnd(); writer.WriteLine(); - string readerClass = "XmlSerializationReader" + suffix; + string readerClass = $"XmlSerializationReader{suffix}"; readerClass = classes.AddUnique(readerClass, readerClass); var readerCodeGen = new XmlSerializationReaderCodeGen(writer, scopes, "public", readerClass); readerCodeGen.GenerateBegin(); @@ -499,10 +499,10 @@ internal static Assembly GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type? ModuleBuilder moduleBuilder = CodeGenerator.CreateModuleBuilder(assemblyBuilder, assemblyName); - string writerClass = "XmlSerializationWriter" + suffix; - writerClass = classes.AddUnique(writerClass, writerClass); - XmlSerializationWriterILGen writerCodeGen = new XmlSerializationWriterILGen(scopes, "public", writerClass); - writerCodeGen.ModuleBuilder = moduleBuilder; + string writerClass = $"XmlSerializationWriter{suffix}"; + writerClass = classes.AddUnique(writerClass, writerClass); + XmlSerializationWriterILGen writerCodeGen = new XmlSerializationWriterILGen(scopes, "public", writerClass); + writerCodeGen.ModuleBuilder = moduleBuilder; writerCodeGen.GenerateBegin(); string[] writeMethodNames = new string[xmlMappings.Length]; @@ -513,9 +513,9 @@ internal static Assembly GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type? } Type writerType = writerCodeGen.GenerateEnd(); - string readerClass = "XmlSerializationReader" + suffix; - readerClass = classes.AddUnique(readerClass, readerClass); - XmlSerializationReaderILGen readerCodeGen = new XmlSerializationReaderILGen(scopes, "public", readerClass); + string readerClass = $"XmlSerializationReader{suffix}"; + readerClass = classes.AddUnique(readerClass, readerClass); + XmlSerializationReaderILGen readerCodeGen = new XmlSerializationReaderILGen(scopes, "public", readerClass); readerCodeGen.ModuleBuilder = moduleBuilder; readerCodeGen.CreatedTypes.Add(writerType.Name, writerType); @@ -551,14 +551,14 @@ private static MethodInfo GetMethodFromType( return method; // Not support pregen. Workaround SecurityCritical required for assembly.CodeBase api. - MissingMethodException missingMethod = new MissingMethodException(type.FullName + "::" + methodName); + MissingMethodException missingMethod = new MissingMethodException($"{type.FullName}::{methodName}"); throw missingMethod; } [RequiresUnreferencedCode("calls GetType")] internal static Type GetTypeFromAssembly(Assembly assembly, string typeName) { - typeName = GeneratedAssemblyNamespace + "." + typeName; + typeName = $"{GeneratedAssemblyNamespace}.{typeName}"; Type? type = assembly.GetType(typeName); if (type == null) throw new InvalidOperationException(SR.Format(SR.XmlMissingType, typeName, assembly.FullName)); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compiler.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compiler.cs index 71e2fdd1ed1fef..7b08dd571daeff 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compiler.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compiler.cs @@ -92,7 +92,9 @@ internal TextWriter Source internal static string GetTempAssemblyName(AssemblyName parent, string? ns) { - return parent.Name + ".XmlSerializers" + (string.IsNullOrEmpty(ns) ? "" : $".{GetPersistentHashCode(ns)}"); + return string.IsNullOrEmpty(ns) ? + $"{parent.Name}.XmlSerializers" : + $"{parent.Name}.XmlSerializers.{GetPersistentHashCode(ns)}"; } private static uint GetPersistentHashCode(string value) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ImportContext.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ImportContext.cs index 61acd28393cbdc..7d042e04787d15 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ImportContext.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ImportContext.cs @@ -135,7 +135,7 @@ internal StringCollection Warnings if (qname == null || qname.IsEmpty) return null; - string key = item.GetType().Name + ":" + qname.ToString(); + string key = $"{item.GetType().Name}:{qname}"; ArrayList? list = (ArrayList?)ObjectCache[key]; if (list == null) { @@ -156,7 +156,7 @@ internal StringCollection Warnings else { Warnings.Add(SR.Format(SR.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace)); - Warnings.Add("DEBUG:Cached item key:\r\n" + (string?)looks[cachedItem] + "\r\nnew item key:\r\n" + (string?)looks[item]); + Warnings.Add($"DEBUG:Cached item key:\r\n{(string?)looks[cachedItem]}\r\nnew item key:\r\n{(string?)looks[item]}"); } } // no match found we need to insert the new type in the cache diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs index 94e612597f270d..0c74ae4944e95e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs @@ -132,11 +132,11 @@ internal string ToString(string? defaultNs) { if (Any) { - return (Namespace == null ? "##any" : Namespace) + ":" + Name; + return $"{(Namespace == null ? "##any" : Namespace)}:{Name}"; } else { - return Namespace == defaultNs ? Name : Namespace + ":" + Name; + return Namespace == defaultNs ? Name : $"{Namespace}:{Name}"; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Models.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Models.cs index f81cf455a7b5e4..8795759b04efc4 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Models.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Models.cs @@ -210,7 +210,7 @@ private void CheckSupportedMember(TypeDesc? typeDesc, MemberInfo member, Type ty { typeDesc.Exception = new NotSupportedException(SR.Format(SR.XmlSerializerUnsupportedType, typeDesc.FullName)); } - throw new InvalidOperationException(SR.Format(SR.XmlSerializerUnsupportedMember, member.DeclaringType!.FullName + "." + member.Name, type.FullName), typeDesc.Exception); + throw new InvalidOperationException(SR.Format(SR.XmlSerializerUnsupportedMember, $"{member.DeclaringType!.FullName}.{member.Name}", type.FullName), typeDesc.Exception); } CheckSupportedMember(typeDesc.BaseTypeDesc, member, type); CheckSupportedMember(typeDesc.ArrayElementTypeDesc, member, type); @@ -300,10 +300,10 @@ internal FieldModel(MemberInfo memberInfo, Type fieldType, TypeDesc fieldTypeDes _fieldType = fieldType; _fieldTypeDesc = fieldTypeDesc; _memberInfo = memberInfo; - _checkShouldPersistMethodInfo = memberInfo.DeclaringType!.GetMethod("ShouldSerialize" + memberInfo.Name, Type.EmptyTypes); + _checkShouldPersistMethodInfo = memberInfo.DeclaringType!.GetMethod($"ShouldSerialize{memberInfo.Name}", Type.EmptyTypes); _checkShouldPersist = _checkShouldPersistMethodInfo != null; - FieldInfo? specifiedField = memberInfo.DeclaringType.GetField(memberInfo.Name + "Specified"); + FieldInfo? specifiedField = memberInfo.DeclaringType.GetField($"{memberInfo.Name}Specified"); if (specifiedField != null) { if (specifiedField.FieldType != typeof(bool)) @@ -315,7 +315,7 @@ internal FieldModel(MemberInfo memberInfo, Type fieldType, TypeDesc fieldTypeDes } else { - PropertyInfo? specifiedProperty = memberInfo.DeclaringType.GetProperty(memberInfo.Name + "Specified"); + PropertyInfo? specifiedProperty = memberInfo.DeclaringType.GetProperty($"{memberInfo.Name}Specified"); if (specifiedProperty != null) { if (StructModel.CheckPropertyRead(specifiedProperty)) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs index 2477f283b01f16..e7c49bc6c0e368 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs @@ -174,7 +174,7 @@ private bool GenerateLiteralMembersElementInternal(MemberMapping[] mappings, boo if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) { - string nameSpecified = mapping.Name + "Specified"; + string nameSpecified = $"{mapping.Name}Specified"; for (int j = 0; j < mappings.Length; j++) { if (mappings[j].Name == nameSpecified) @@ -379,7 +379,7 @@ private object GenerateEncodedMembersElement(XmlMembersMapping xmlMembersMapping members[index] = member; if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) { - string nameSpecified = mapping.Name + "Specified"; + string nameSpecified = $"{mapping.Name}Specified"; for (int j = 0; j < mappings.Length; j++) { if (mappings[j].Name == nameSpecified) @@ -1239,7 +1239,7 @@ private object WritePrimitive(TypeMapping mapping, Func readFunc } else { - string methodName = "To" + mapping.TypeDesc.FormatterName; + string methodName = $"To{mapping.TypeDesc.FormatterName}"; MethodInfo? method = typeof(XmlSerializationReader).GetMethod(methodName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[] { typeof(string) }); if (method == null) { @@ -1741,8 +1741,8 @@ void Wrapper(object? collection, object? collectionItems) [RequiresUnreferencedCode("calls GetType on object")] void Wrapper(object? _) { - string specifiedMemberName = member.Mapping.Name + "Specified"; - MethodInfo? specifiedMethodInfo = o!.GetType().GetMethod("set_" + specifiedMemberName); + string specifiedMemberName = $"{member.Mapping.Name}Specified"; + MethodInfo? specifiedMethodInfo = o!.GetType().GetMethod($"set_{specifiedMemberName}"); if (specifiedMethodInfo != null) { specifiedMethodInfo.Invoke(o, new object[] { true }); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationWriter.cs index 78595d0cc35c10..92f54f923386f5 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationWriter.cs @@ -587,13 +587,13 @@ private void WriteStructMethod(StructMapping mapping, string n, string? ns, obje bool shouldPersist = true; if (m.CheckSpecified != SpecifiedAccessor.None) { - string specifiedMemberName = m.Name + "Specified"; + string specifiedMemberName = $"{m.Name}Specified"; isSpecified = (bool)GetMemberValue(o!, specifiedMemberName)!; } if (m.CheckShouldPersist) { - string methodInvoke = "ShouldSerialize" + m.Name; + string methodInvoke = $"ShouldSerialize{m.Name}"; MethodInfo method = o!.GetType().GetMethod(methodInvoke, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)!; shouldPersist = (bool)method.Invoke(o, Array.Empty())!; } @@ -619,13 +619,13 @@ private void WriteStructMethod(StructMapping mapping, string n, string? ns, obje bool shouldPersist = true; if (m.CheckSpecified != SpecifiedAccessor.None) { - string specifiedMemberName = m.Name + "Specified"; + string specifiedMemberName = $"{m.Name}Specified"; isSpecified = (bool)GetMemberValue(o!, specifiedMemberName)!; } if (m.CheckShouldPersist) { - string methodInvoke = "ShouldSerialize" + m.Name; + string methodInvoke = $"ShouldSerialize{m.Name}"; MethodInfo method = o!.GetType().GetMethod(methodInvoke, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)!; shouldPersist = (bool)method.Invoke(o, Array.Empty())!; } @@ -1230,7 +1230,7 @@ private void GenerateMembersElement(object o, XmlMembersMapping xmlMembersMappin bool? specifiedSource = null; if (member.CheckSpecified != SpecifiedAccessor.None) { - string memberNameSpecified = member.Name + "Specified"; + string memberNameSpecified = $"{member.Name}Specified"; for (int j = 0; j < Math.Min(pLength, mapping.Members.Length); j++) { if (mapping.Members[j].Name == memberNameSpecified) @@ -1261,7 +1261,7 @@ private void GenerateMembersElement(object o, XmlMembersMapping xmlMembersMappin bool? specifiedSource = null; if (member.CheckSpecified != SpecifiedAccessor.None) { - string memberNameSpecified = member.Name + "Specified"; + string memberNameSpecified = $"{member.Name}Specified"; for (int j = 0; j < Math.Min(pLength, mapping.Members.Length); j++) { if (mapping.Members[j].Name == memberNameSpecified) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs index 49585a4ec46302..93675ac7978664 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs @@ -34,7 +34,7 @@ public int Compare(object? o1, object? o2) { XmlSchemaFacet f1 = (XmlSchemaFacet)o1!; XmlSchemaFacet f2 = (XmlSchemaFacet)o2!; - return string.Compare(f1.GetType().Name + ":" + f1.Value, f2.GetType().Name + ":" + f2.Value, StringComparison.Ordinal); + return string.Compare($"{f1.GetType().Name}:{f1.Value}", $"{f2.GetType().Name}:{f2.Value}", StringComparison.Ordinal); } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SoapReflectionImporter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SoapReflectionImporter.cs index 1dcd50b7ab04a7..d19f60ae5aeb27 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SoapReflectionImporter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SoapReflectionImporter.cs @@ -502,7 +502,7 @@ private void SetArrayMappingType(ArrayMapping mapping) } itemTypeName = CodeIdentifier.MakePascal(itemTypeName); - string uniqueName = "ArrayOf" + itemTypeName; + string uniqueName = $"ArrayOf{itemTypeName}"; string ns = useDefaultNs ? _defaultNs : itemTypeNamespace; int i = 1; TypeMapping? existingMapping = (TypeMapping?)_types[uniqueName, ns]; @@ -784,7 +784,7 @@ internal string XsdTypeName(Type type, SoapAttributes a, string name) for (int i = 0; i < names.Length; i++) { - string argument = "{" + names[i] + "}"; + string argument = $"{{{names[i]}}}"; if (typeName.Contains(argument)) { typeName = typeName.Replace(argument, XsdTypeName(types[i])); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs index 5b4e7fec3459e4..a8c6256b762268 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs @@ -49,7 +49,7 @@ public SourceInfo(string source, string? arg, MemberInfo? memberInfo, public SourceInfo CastTo(TypeDesc td) { - return new SourceInfo("((" + td.CSharpName + ")" + Source + ")", Arg, MemberInfo, td.Type!, ILG); + return new SourceInfo($"(({td.CSharpName}){Source})", Arg, MemberInfo, td.Type!, ILG); } [RequiresUnreferencedCode("calls InternalLoad")] diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Types.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Types.cs index 4597c97812f95a..62c4a5cffaa9a4 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Types.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Types.cs @@ -375,7 +375,7 @@ internal TypeDesc GetNullableTypeDesc( if (_nullableTypeDesc == null) { - _nullableTypeDesc = new TypeDesc("NullableOf" + _name, "System.Nullable`1[" + _fullName + "]", null, TypeKind.Struct, this, _flags | TypeFlags.OptionalValue, _formatterName); + _nullableTypeDesc = new TypeDesc($"NullableOf{_name}", $"System.Nullable`1[{_fullName}]", null, TypeKind.Struct, this, _flags | TypeFlags.OptionalValue, _formatterName); _nullableTypeDesc._type = type; } @@ -423,7 +423,7 @@ internal int Weight internal TypeDesc CreateArrayTypeDesc() { if (_arrayTypeDesc == null) - _arrayTypeDesc = new TypeDesc(null, _name + "[]", _fullName + "[]", TypeKind.Array, null, TypeFlags.Reference | (_flags & TypeFlags.UseReflection), this); + _arrayTypeDesc = new TypeDesc(null, $"{_name}[]", $"{_fullName}[]", TypeKind.Array, null, TypeFlags.Reference | (_flags & TypeFlags.UseReflection), this); return _arrayTypeDesc; } @@ -849,7 +849,7 @@ private TypeDesc ImportTypeDesc(Type type, MemberInfo? memberInfo, bool directRe else if (typeof(ICollection).IsAssignableFrom(type) && !IsArraySegment(type)) { kind = TypeKind.Collection; - arrayElementType = GetCollectionElementType(type, memberInfo == null ? null : memberInfo.DeclaringType!.FullName + "." + memberInfo.Name); + arrayElementType = GetCollectionElementType(type, memberInfo == null ? null : $"{memberInfo.DeclaringType!.FullName}.{memberInfo.Name}"); flags |= GetConstructorFlags(type, ref exception); } else if (type == typeof(XmlQualifiedName)) @@ -922,7 +922,7 @@ private TypeDesc ImportTypeDesc(Type type, MemberInfo? memberInfo, bool directRe } else { - exception = new NotSupportedException(SR.Format(SR.XmlUnsupportedInterfaceDetails, memberInfo.DeclaringType!.FullName + "." + memberInfo.Name, type.FullName)); + exception = new NotSupportedException(SR.Format(SR.XmlUnsupportedInterfaceDetails, $"{memberInfo.DeclaringType!.FullName}.{memberInfo.Name}", type.FullName)); } } } @@ -1016,7 +1016,7 @@ internal static string TypeName(Type t) { if (t.IsArray) { - return "ArrayOf" + TypeName(t.GetElementType()!); + return $"ArrayOf{TypeName(t.GetElementType()!)}"; } else if (t.IsGenericType) { @@ -1152,7 +1152,7 @@ private static void PopulateMemberInfos(StructMapping structMapping, MemberMappi if (mappings[i].ChoiceIdentifier != null) memberInfos[mappings[i].ChoiceIdentifier!.MemberName!] = mappings[i].ChoiceIdentifier!.MemberInfo!; if (mappings[i].CheckSpecifiedMemberInfo != null) - memberInfos[mappings[i].Name + "Specified"] = mappings[i].CheckSpecifiedMemberInfo!; + memberInfos[$"{mappings[i].Name}Specified"] = mappings[i].CheckSpecifiedMemberInfo!; } // The scenario here is that user has one base class A and one derived class B and wants to serialize/deserialize an object of B. diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlMapping.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlMapping.cs index 2f28a383dd7c72..3911d54099085e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlMapping.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlMapping.cs @@ -117,7 +117,7 @@ internal static string GenerateKey(Type type, XmlRootAttribute? root, string? ns { root = (XmlRootAttribute?)XmlAttributes.GetAttr(type, typeof(XmlRootAttribute)); } - return type.FullName + ":" + (root == null ? string.Empty : root.GetKey()) + ":" + (ns == null ? string.Empty : ns); + return $"{type.FullName}:{(root == null ? string.Empty : root.GetKey())}:{(ns == null ? string.Empty : ns)}"; } internal string? Key { get { return _key; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs index aed094a06649af..69f23fc7ea41a1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs @@ -975,7 +975,7 @@ internal string XsdTypeName(Type type, XmlAttributes a, string name) for (int i = 0; i < names.Length; i++) { - string argument = "{" + names[i] + "}"; + string argument = $"{{{names[i]}}}"; if (typeName.Contains(argument)) { typeName = typeName.Replace(argument, XsdTypeName(types[i])); @@ -1054,7 +1054,7 @@ private void SetArrayMappingType(ArrayMapping mapping, string? defaultNs, Type t else { ns = defaultNs; - name = "Choice" + (_choiceNum++); + name = $"Choice{(_choiceNum++)}"; } if (name == null) @@ -1066,7 +1066,7 @@ private void SetArrayMappingType(ArrayMapping mapping, string? defaultNs, Type t if (ns == null) ns = defaultNs; - string uniqueName = name = generateTypeName ? "ArrayOf" + CodeIdentifier.MakePascal(name) : name; + string uniqueName = name = generateTypeName ? $"ArrayOf{CodeIdentifier.MakePascal(name)}" : name; int i = 1; TypeMapping? existingMapping = (TypeMapping?)_types[uniqueName, ns]; while (existingMapping != null) @@ -1397,7 +1397,7 @@ private MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMembe internal static XmlReflectionMember? FindSpecifiedMember(string memberName, XmlReflectionMember[] reflectionMembers) { for (int i = 0; i < reflectionMembers.Length; i++) - if (string.Equals(reflectionMembers[i].MemberName, memberName + "Specified", StringComparison.Ordinal)) + if (string.Equals(reflectionMembers[i].MemberName, $"{memberName}Specified", StringComparison.Ordinal)) return reflectionMembers[i]; return null; } @@ -1564,7 +1564,7 @@ private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, Xml if (accessor.TypeDesc.IsArrayLike) { - Type arrayElementType = TypeScope.GetArrayElementType(accessorType, model.FieldTypeDesc.FullName + "." + model.Name)!; + Type arrayElementType = TypeScope.GetArrayElementType(accessorType, $"{model.FieldTypeDesc.FullName}.{model.Name}")!; if ((flags & attrFlags) != 0) { @@ -2027,7 +2027,7 @@ private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, Xml } else { - string id = element.Namespace != null && element.Namespace.Length > 0 ? element.Namespace + ":" + element.Name : element.Name; + string id = element.Namespace != null && element.Namespace.Length > 0 ? $"{element.Namespace}:{element.Name}" : element.Name; // Type {0} is missing value for '{1}'. throw new InvalidOperationException(SR.Format(SR.XmlChoiceMissingValue, accessor.ChoiceIdentifier.Mapping!.TypeDesc!.FullName, id, element.Name, element.Namespace)); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlRootAttribute.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlRootAttribute.cs index 039d97f0594aa4..2813d23ea30eb0 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlRootAttribute.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlRootAttribute.cs @@ -92,7 +92,7 @@ internal bool GetIsNullableSpecified() internal string Key { - get { return (_ns == null ? string.Empty : _ns) + ":" + ElementName + ":" + _nullable.ToString(); } + get { return $"{(_ns == null ? string.Empty : _ns)}:{ElementName}:{_nullable}"; } } internal string GetKey() diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaExporter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaExporter.cs index 839ddc19cd805a..b5a0098a700a7a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaExporter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaExporter.cs @@ -147,7 +147,7 @@ public string ExportAnyType(string? ns) if (IsAnyType(schemaType, true, true)) return name; i++; - name = "any" + i.ToString(CultureInfo.InvariantCulture); + name = string.Create(CultureInfo.InvariantCulture, $"any{i}"); } } @@ -572,7 +572,7 @@ private XmlSchemaType ExportAnonymousPrimitiveMapping(PrimitiveMapping mapping) } else { - throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, "Unsupported anonymous mapping type: " + mapping.ToString())); + throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, $"Unsupported anonymous mapping type: {mapping}")); } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaImporter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaImporter.cs index 9aaf0a36c814a1..b9020be08972f8 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaImporter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaImporter.cs @@ -832,9 +832,9 @@ private MemberMapping ImportChoiceGroup(XmlSchemaGroupBase group, string identif if (duplicateTypes) { member.ChoiceIdentifier = new ChoiceIdentifierAccessor(); - member.ChoiceIdentifier.MemberName = member.Name + "ElementName"; + member.ChoiceIdentifier.MemberName = $"{member.Name}ElementName"; // we need to create the EnumMapping to store all of the element names - member.ChoiceIdentifier.Mapping = ImportEnumeratedChoice(member.Elements, ns, member.Name + "ChoiceType"); + member.ChoiceIdentifier.Mapping = ImportEnumeratedChoice(member.Elements, ns, $"{member.Name}ChoiceType"); member.ChoiceIdentifier.MemberIds = new string[member.Elements.Length]; ConstantMapping[] constants = ((EnumMapping)member.ChoiceIdentifier.Mapping).Constants!; for (int i = 0; i < member.Elements.Length; i++) @@ -1296,7 +1296,7 @@ private ElementAccessor[] ImportAny(XmlSchemaAny any, bool makeElement, string? if (choiceMember.ChoiceIdentifier != null) return null; arrayMapping.TypeDesc = choiceMember.TypeDesc; arrayMapping.Elements = choiceMember.Elements; - arrayMapping.TypeName = (type.Name == null || type.Name.Length == 0) ? "ArrayOf" + CodeIdentifier.MakePascal(arrayMapping.TypeDesc!.Name) : type.Name; + arrayMapping.TypeName = (type.Name == null || type.Name.Length == 0) ? $"ArrayOf{CodeIdentifier.MakePascal(arrayMapping.TypeDesc!.Name)}" : type.Name; } else if (item is XmlSchemaAll || item is XmlSchemaSequence) { @@ -1313,7 +1313,7 @@ private ElementAccessor[] ImportAny(XmlSchemaAny any, bool makeElement, string? return null; arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = ((TypeMapping)itemAccessor.Mapping!).TypeDesc!.CreateArrayTypeDesc(); - arrayMapping.TypeName = (type.Name == null || type.Name.Length == 0) ? "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeDesc.Name) : type.Name; + arrayMapping.TypeName = (type.Name == null || type.Name.Length == 0) ? $"ArrayOf{CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeDesc.Name)}" : type.Name; } else { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemas.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemas.cs index fc4804211b704a..94fdb0a374c933 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemas.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSchemas.cs @@ -614,8 +614,7 @@ private static string Dump(XmlSchemaObject o) private static string MergeFailedMessage(XmlSchemaObject src, XmlSchemaObject dest, string? ns) { string err = SR.Format(SR.XmlSerializableMergeItem, ns, GetSchemaItem(src, ns, null)); - err += "\r\n" + Dump(src); - err += "\r\n" + Dump(dest); + err += $"{Environment.NewLine}{Dump(src)}{Environment.NewLine}{Dump(dest)}"; return err; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationGeneratedCode.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationGeneratedCode.cs index 60b8eb8a408199..49bc01a5606474 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationGeneratedCode.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationGeneratedCode.cs @@ -247,7 +247,7 @@ internal string GenerateBaseSerializer(string baseSerializer, string readerClass internal string GenerateTypedSerializer(string? readMethod, string? writeMethod, XmlMapping mapping, CodeIdentifiers classes, string baseSerializer, string readerClass, string writerClass) { string serializerName = CodeIdentifier.MakeValid(Accessor.UnescapeName(mapping.Accessor.Mapping!.TypeDesc!.Name)); - serializerName = classes.AddUnique(serializerName + "Serializer", mapping); + serializerName = classes.AddUnique($"{serializerName}Serializer", mapping); _writer.WriteLine(); _writer.Write("public sealed class "); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs index dfee0a19dbdb33..4fdcd7c5af36f1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationILGen.cs @@ -168,7 +168,7 @@ internal FieldBuilder GenerateHashtableGetBegin(string privateName, string publi ilg.BeginMethod( typeof(Hashtable), - "get_" + publicName, + $"get_{publicName}", Type.EmptyTypes, Array.Empty(), CodeGenerator.PublicOverrideMethodAttributes | MethodAttributes.SpecialName); @@ -325,7 +325,7 @@ internal string GenerateBaseSerializer(string baseSerializer, string readerClass internal string GenerateTypedSerializer(string readMethod, string writeMethod, XmlMapping mapping, CodeIdentifiers classes, string baseSerializer, string readerClass, string writerClass) { string serializerName = CodeIdentifier.MakeValid(Accessor.UnescapeName(mapping.Accessor.Mapping!.TypeDesc!.Name)); - serializerName = classes.AddUnique(serializerName + "Serializer", mapping); + serializerName = classes.AddUnique($"{serializerName}Serializer", mapping); TypeBuilder typedSerializerTypeBuilder = CodeGenerator.CreateTypeBuilder( _moduleBuilder!, diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs index 0ea4307b42ad15..52e70f990d16f2 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs @@ -792,12 +792,11 @@ protected void ParseWsdlArrayType(XmlAttribute attr) int colon = attr.Value.LastIndexOf(':'); if (colon < 0) { - attr.Value = _r.LookupNamespace("") + ":" + attr.Value; + attr.Value = $"{_r.LookupNamespace("")}:{attr.Value}"; } else { - attr.Value = string.Concat(_r.LookupNamespace(attr.Value.Substring(0, colon)), ":", - attr.Value.AsSpan(colon + 1)); + attr.Value = $"{_r.LookupNamespace(attr.Value.Substring(0, colon))}:{attr.Value.AsSpan(colon + 1)}"; } } return; @@ -1287,7 +1286,7 @@ protected void UnreferencedObject(string? id, object? o) private string CurrentTag() => _r.NodeType switch { - XmlNodeType.Element => "<" + _r.LocalName + " xmlns='" + _r.NamespaceURI + "'>", + XmlNodeType.Element => $"<{_r.LocalName} xmlns='{_r.NamespaceURI}'>", XmlNodeType.EndElement => ">", XmlNodeType.Text => _r.Value, XmlNodeType.CDATA => "CDATA", @@ -2129,8 +2128,8 @@ internal Member(XmlSerializationReaderCodeGen outerClass, string source, string? internal Member(XmlSerializationReaderCodeGen outerClass, string source, string? arraySource, string? arrayName, int i, MemberMapping mapping, bool multiRef, string? choiceSource) { _source = source; - _arrayName = arrayName + "_" + i.ToString(CultureInfo.InvariantCulture); - _choiceArrayName = "choice_" + _arrayName; + _arrayName = string.Create(CultureInfo.InvariantCulture, $"{arrayName}_{i}"); + _choiceArrayName = $"choice_{_arrayName}"; _choiceSource = choiceSource; if (mapping.TypeDesc!.IsArrayLike) @@ -2146,14 +2145,13 @@ internal Member(XmlSerializationReaderCodeGen outerClass, string source, string? _choiceArraySource = outerClass.GetArraySource(mapping.TypeDesc, _choiceArrayName, multiRef); string a = _choiceArrayName; - string c = "c" + a; + string c = $"c{a}"; bool choiceUseReflection = mapping.ChoiceIdentifier.Mapping!.TypeDesc!.UseReflection; string choiceTypeFullName = mapping.ChoiceIdentifier.Mapping.TypeDesc.CSharpName; - string castString = choiceUseReflection ? "" : "(" + choiceTypeFullName + "[])"; + string castString = choiceUseReflection ? "" : $"({choiceTypeFullName}[])"; - string init = a + " = " + castString + - "EnsureArrayIndex(" + a + ", " + c + ", " + outerClass.RaCodeGen.GetStringForTypeof(choiceTypeFullName, choiceUseReflection) + ");"; - _choiceArraySource = init + outerClass.RaCodeGen.GetStringForArrayMember(a, c + "++", mapping.ChoiceIdentifier.Mapping.TypeDesc); + string init = $"{a} = {castString}EnsureArrayIndex({a}, {c}, {outerClass.RaCodeGen.GetStringForTypeof(choiceTypeFullName, choiceUseReflection)});"; + _choiceArraySource = init + outerClass.RaCodeGen.GetStringForArrayMember(a, $"{c}++", mapping.ChoiceIdentifier.Mapping.TypeDesc); } else { @@ -2539,7 +2537,7 @@ private string GenerateLiteralMembersElement(XmlMembersMapping xmlMembersMapping member.ParamsReadSource = $"paramsRead[{i}]"; if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) { - string nameSpecified = mapping.Name + "Specified"; + string nameSpecified = $"{mapping.Name}Specified"; for (int j = 0; j < mappings.Length; j++) { if (mappings[j].Name == nameSpecified) @@ -2616,7 +2614,7 @@ private string GenerateLiteralMembersElement(XmlMembersMapping xmlMembersMapping WriteWhileNotLoopStart(); Writer.Indent++; - string unknownNode = "UnknownNode((object)p, " + ExpectedElements(members) + ");"; + string unknownNode = $"UnknownNode((object)p, {ExpectedElements(members)});"; WriteMemberElements(members, unknownNode, unknownNode, anyElement, anyText, null); Writer.WriteLine("Reader.MoveToContent();"); @@ -2719,7 +2717,7 @@ private string GenerateEncodedMembersElement(XmlMembersMapping xmlMembersMapping if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) { - string nameSpecified = mapping.Name + "Specified"; + string nameSpecified = $"{mapping.Name}Specified"; for (int j = 0; j < mappings.Length; j++) { if (mappings[j].Name == nameSpecified) @@ -2731,7 +2729,7 @@ private string GenerateEncodedMembersElement(XmlMembersMapping xmlMembersMapping } } - string fixupMethodName = "fixup_" + methodName; + string fixupMethodName = $"fixup_{methodName}"; bool anyFixups = WriteMemberFixupBegin(members, fixupMethodName, "p"); if (members.Length > 0 && members[0].Mapping.IsReturnValue) Writer.WriteLine("IsReturnValue = true;"); @@ -2770,7 +2768,7 @@ private string GenerateEncodedMembersElement(XmlMembersMapping xmlMembersMapping private void WriteCreateCollection(TypeDesc td, string source) { bool useReflection = td.UseReflection; - string item = (td.ArrayElementTypeDesc == null ? "object" : td.ArrayElementTypeDesc.CSharpName) + "[]"; + string item = $"{(td.ArrayElementTypeDesc == null ? "object" : td.ArrayElementTypeDesc.CSharpName)}[]"; bool arrayElementUseReflection = td.ArrayElementTypeDesc == null ? false : td.ArrayElementTypeDesc.UseReflection; //cannot call WriteArrayLocalDecl since 'ci' is always @@ -2780,7 +2778,7 @@ private void WriteCreateCollection(TypeDesc td, string source) Writer.Write(item); Writer.Write(" "); Writer.Write("ci ="); - Writer.Write("(" + item + ")"); + Writer.Write($"({item})"); Writer.Write(source); Writer.WriteLine(";"); @@ -2793,7 +2791,7 @@ private void WriteCreateCollection(TypeDesc td, string source) if (!arrayElementUseReflection) Writer.Write("ci[i]"); else - Writer.Write(RaCodeGen.GetReflectionVariable(typeof(Array).FullName!, "0") + "[ci , i]"); + Writer.Write($"{RaCodeGen.GetReflectionVariable(typeof(Array).FullName!, "0")}[ci , i]"); if (useReflection) Writer.WriteLine("}"); @@ -2819,7 +2817,7 @@ private string GenerateTypeElement(XmlTypeMapping xmlTypeMapping) member.Elements = new ElementAccessor[] { element }; Member[] members = new Member[] { new Member(this, "o", "o", "a", 0, member) }; Writer.WriteLine("Reader.MoveToContent();"); - string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");"; + string unknownNode = $"UnknownNode(null, {ExpectedElements(members)});"; WriteMemberElements(members, "throw CreateUnknownNodeException();", unknownNode, element.Any ? members[0] : null, null, null); if (element.IsSoap) { @@ -2914,9 +2912,9 @@ private void WritePrimitive(TypeMapping mapping, string source) private string WriteHashtable(EnumMapping mapping, string typeName) { CodeIdentifier.CheckValidIdentifier(typeName); - string? propName = MakeUnique(mapping, typeName + "Values"); + string? propName = MakeUnique(mapping, $"{typeName}Values"); if (propName == null) return CodeIdentifier.GetCSharpName(typeName); - string? memberName = MakeUnique(mapping, "_" + propName); + string? memberName = MakeUnique(mapping, $"_{propName}"); propName = CodeIdentifier.GetCSharpName(propName); Writer.WriteLine(); @@ -3092,7 +3090,7 @@ private void WriteDerivedTypes(StructMapping mapping, bool isTypedReturn, string Writer.Write("return "); if (derived.TypeDesc!.UseReflection && isTypedReturn) - Writer.Write("(" + returnTypeName + ")"); + Writer.Write($"({returnTypeName})"); Writer.Write(methodName); Writer.Write("("); if (derived.TypeDesc.IsNullable) @@ -3259,7 +3257,7 @@ private void WriteLiteralStructMethod(StructMapping structMapping) Writer.Indent++; Writer.WriteLine("if (isNull) {"); Writer.Indent++; - Writer.WriteLine("if (xsiType != null) return (" + typeName + ")ReadTypedNull(xsiType);"); + Writer.WriteLine($"if (xsiType != null) return ({typeName})ReadTypedNull(xsiType);"); Writer.Write("else return "); if (structMapping.TypeDesc.IsValueType) { @@ -3282,7 +3280,7 @@ private void WriteLiteralStructMethod(StructMapping structMapping) if (structMapping.TypeDesc.IsRoot) { Writer.Indent++; - Writer.WriteLine("return ReadTypedPrimitive(new System.Xml.XmlQualifiedName(\"" + Soap.UrType + "\", \"" + XmlSchema.Namespace + "\"));"); + Writer.WriteLine($"return ReadTypedPrimitive(new System.Xml.XmlQualifiedName(\"{Soap.UrType}\", \"{XmlSchema.Namespace}\"));"); Writer.Indent--; } Writer.WriteLine("}"); @@ -3341,7 +3339,7 @@ private void WriteLiteralStructMethod(StructMapping structMapping) member.ParamsReadSource = $"paramsRead[{i}]"; member.IsNullable = mapping.TypeDesc!.IsNullable; if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) - member.CheckSpecifiedSource = RaCodeGen.GetStringForMember("o", mapping.Name + "Specified", structMapping.TypeDesc); + member.CheckSpecifiedSource = RaCodeGen.GetStringForMember("o", $"{mapping.Name}Specified", structMapping.TypeDesc); if (mapping.Text != null) anyText = member; if (mapping.Attribute != null && mapping.Attribute.Any) @@ -3423,7 +3421,7 @@ private void WriteLiteralStructMethod(StructMapping structMapping) } WriteWhileNotLoopStart(); Writer.Indent++; - string unknownNode = "UnknownNode((object)o, " + ExpectedElements(allMembers) + ");"; + string unknownNode = $"UnknownNode((object)o, {ExpectedElements(allMembers)});"; WriteMemberElements(allMembers, unknownNode, unknownNode, anyElement, anyText, null); Writer.WriteLine("Reader.MoveToContent();"); @@ -3478,13 +3476,13 @@ private void WriteEncodedStructMethod(StructMapping structMapping) string source = RaCodeGen.GetStringForMember("o", mapping.Name, structMapping.TypeDesc); Member member = new Member(this, source, source, "a", i, mapping, GetChoiceIdentifierSource(mapping, "o", structMapping.TypeDesc)); if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) - member.CheckSpecifiedSource = RaCodeGen.GetStringForMember("o", mapping.Name + "Specified", structMapping.TypeDesc); + member.CheckSpecifiedSource = RaCodeGen.GetStringForMember("o", $"{mapping.Name}Specified", structMapping.TypeDesc); if (!mapping.IsSequence) member.ParamsReadSource = $"paramsRead[{i}]"; members[i] = member; } - fixupMethodName = "fixup_" + methodName; + fixupMethodName = $"fixup_{methodName}"; anyFixups = WriteMemberFixupBegin(members, fixupMethodName, "o"); // we're able to not do WriteMemberBegin here because we don't allow arrays as attributes @@ -3537,7 +3535,7 @@ private void WriteFixupMethod(string? fixupMethodName, Member[] members, string string memberSource = /*member.IsList ? source + ".Add(" :*/ member.ArraySource; - string targetSource = "GetTarget(ids[" + fixupIndex + "])"; + string targetSource = $"GetTarget(ids[{fixupIndex}])"; TypeDesc td = member.Mapping.TypeDesc!; if (td.IsCollection || td.IsEnumerable) { @@ -3566,7 +3564,7 @@ private void WriteFixupMethod(string? fixupMethodName, Member[] members, string if (typed) { - WriteCatchCastException(member.Mapping.TypeDesc!, targetSource, "ids[" + fixupIndex + "]"); + WriteCatchCastException(member.Mapping.TypeDesc!, targetSource, $"ids[{fixupIndex}]"); } } Writer.Indent--; @@ -3764,7 +3762,7 @@ private void WriteAttributes(Member[] members, Member? anyAttribute, string else Writer.WriteLine("();"); //Writer.Write(xmlnsMember.ArraySource); - Writer.Write("((" + xmlnsMember.Mapping.TypeDesc.CSharpName + ")" + xmlnsMember.ArraySource + ")"); + Writer.Write($"(({xmlnsMember.Mapping.TypeDesc.CSharpName}){xmlnsMember.ArraySource})"); Writer.WriteLine(".Add(Reader.Name.Length == 5 ? \"\" : Reader.LocalName, Reader.Value);"); Writer.Indent--; @@ -3803,7 +3801,7 @@ private void WriteAttributes(Member[] members, Member? anyAttribute, string else AttributeAccessor attribute = (AttributeAccessor)attributes[i]!; if (i > 0) qnames += ", "; - qnames += attribute.IsSpecialXmlNamespace ? XmlReservedNs.NsXml : (attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : "") + ":" + attribute.Name; + qnames += attribute.IsSpecialXmlNamespace ? XmlReservedNs.NsXml : $"{(attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : "")}:{attribute.Name}"; } WriteQuotedCSharpString(qnames); } @@ -3931,7 +3929,7 @@ private void WriteMemberBegin(Member[] members) if (member.IsArrayLike) { string a = member.ArrayName; - string c = "c" + a; + string c = $"c{a}"; TypeDesc typeDesc = member.Mapping.TypeDesc!; string typeDescFullName = typeDesc.CSharpName; @@ -3946,7 +3944,7 @@ private void WriteMemberBegin(Member[] members) if (member.Mapping.ChoiceIdentifier != null) { - WriteArrayLocalDecl(member.Mapping.ChoiceIdentifier.Mapping!.TypeDesc!.CSharpName + "[]", + WriteArrayLocalDecl($"{member.Mapping.ChoiceIdentifier.Mapping!.TypeDesc!.CSharpName}[]", member.ChoiceArrayName, "null", member.Mapping.ChoiceIdentifier.Mapping.TypeDesc); Writer.Write("int c"); @@ -4022,7 +4020,7 @@ private string ExpectedElements(Member[] members) if (!firstElement) qnames += ", "; - qnames += ns + ":" + e.Name; + qnames += $"{ns}:{e.Name}"; firstElement = false; } } @@ -4047,7 +4045,7 @@ private void WriteMemberElements(Member[] members, string elementElseString, str if (checkType) { - WriteIfNotSoapRoot(elementElseString + " continue;"); + WriteIfNotSoapRoot($"{elementElseString} continue;"); WriteMemberElementsCheckType(checkTypeHrefsSource); } else @@ -4315,7 +4313,7 @@ private void WriteMemberElementsIf(Member[] members, Member? anyElement, string { WriteSourceBegin(member.ArraySource); TypeDesc td = ((NullableMapping)e.Mapping).BaseMapping!.TypeDesc!; - Writer.Write(RaCodeGen.GetStringForCreateInstance(e.Mapping.TypeDesc.CSharpName, e.Mapping.TypeDesc.UseReflection, false, true, "(" + td.CSharpName + ")" + checkTypeSource)); + Writer.Write(RaCodeGen.GetStringForCreateInstance(e.Mapping.TypeDesc.CSharpName, e.Mapping.TypeDesc.UseReflection, false, true, $"({td.CSharpName}){checkTypeSource}")); } else { @@ -4410,26 +4408,25 @@ private string GetArraySource(TypeDesc typeDesc, string arrayName) private string GetArraySource(TypeDesc typeDesc, string arrayName, bool multiRef) { string a = arrayName; - string c = "c" + a; + string c = $"c{a}"; string init = ""; if (multiRef) { - init = "soap = (System.Object[])EnsureArrayIndex(soap, " + c + "+2, typeof(System.Object)); "; + init = $"soap = (System.Object[])EnsureArrayIndex(soap, {c}+2, typeof(System.Object)); "; } bool useReflection = typeDesc.UseReflection; if (typeDesc.IsArray) { string arrayTypeFullName = typeDesc.ArrayElementTypeDesc!.CSharpName; bool arrayUseReflection = typeDesc.ArrayElementTypeDesc.UseReflection; - string castString = useReflection ? "" : "(" + arrayTypeFullName + "[])"; - init = init + a + " = " + castString + - "EnsureArrayIndex(" + a + ", " + c + ", " + RaCodeGen.GetStringForTypeof(arrayTypeFullName, arrayUseReflection) + ");"; - string arraySource = RaCodeGen.GetStringForArrayMember(a, c + "++", typeDesc); + string castString = useReflection ? "" : $"({arrayTypeFullName}[])"; + init = $"{init}{a} = {castString}EnsureArrayIndex({a}, {c}, {RaCodeGen.GetStringForTypeof(arrayTypeFullName, arrayUseReflection)});"; + string arraySource = RaCodeGen.GetStringForArrayMember(a, $"{c}++", typeDesc); if (multiRef) { - init = init + " soap[1] = " + a + ";"; - init = init + " if (ReadReference(out soap[" + c + "+2])) " + arraySource + " = null; else "; + init = $"{init} soap[1] = {a};"; + init = $"{init} if (ReadReference(out soap[{c}+2])) {arraySource} = null; else "; } return init + arraySource; } @@ -4463,12 +4460,12 @@ private void WriteMemberEnd(Member[] members, bool soapRefs) Writer.Write(" soap[1] = "); string a = member.ArrayName; - string c = "c" + a; + string c = $"c{a}"; bool arrayUseReflection = typeDesc.ArrayElementTypeDesc!.UseReflection; string arrayTypeFullName = typeDesc.ArrayElementTypeDesc.CSharpName; if (!arrayUseReflection) - Writer.Write("(" + arrayTypeFullName + "[])"); + Writer.Write($"({arrayTypeFullName}[])"); Writer.Write("ShrinkArray("); Writer.Write(a); Writer.Write(", "); @@ -4485,12 +4482,12 @@ private void WriteMemberEnd(Member[] members, bool soapRefs) { WriteSourceBegin(member.ChoiceSource!); a = member.ChoiceArrayName; - c = "c" + a; + c = $"c{a}"; bool choiceUseReflection = member.Mapping.ChoiceIdentifier.Mapping!.TypeDesc!.UseReflection; string choiceTypeName = member.Mapping.ChoiceIdentifier.Mapping.TypeDesc.CSharpName; if (!choiceUseReflection) - Writer.Write("(" + choiceTypeName + "[])"); + Writer.Write($"({choiceTypeName}[])"); Writer.Write("ShrinkArray("); Writer.Write(a); Writer.Write(", "); @@ -4619,7 +4616,7 @@ private void WriteArray(string source, string? arrayName, ArrayMapping arrayMapp WriteWhileNotLoopStart(); Writer.Indent++; - string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");"; + string unknownNode = $"UnknownNode(null, {ExpectedElements(members)});"; WriteMemberElements(members, unknownNode, unknownNode, null, null, null); Writer.WriteLine("Reader.MoveToContent();"); @@ -4954,7 +4951,7 @@ private void WriteDerivedSerializable(SerializableMapping head, SerializableMapp } else { - Writer.WriteLine("// " + "missing real mapping for " + derived.XsiType); + Writer.WriteLine($"// missing real mapping for {derived.XsiType}"); Writer.Write("throw CreateMissingIXmlSerializableType("); WriteQuotedCSharpString(derived.XsiType.Name); Writer.Write(", "); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs index 73af82643af97d..60701eeba407bb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReaderILGen.cs @@ -76,8 +76,8 @@ internal Member(XmlSerializationReaderILGen outerClass, string source, string? a internal Member(XmlSerializationReaderILGen outerClass, string source, string? arraySource, string? arrayName, int i, MemberMapping mapping, bool multiRef, string? choiceSource) { _source = source; - _arrayName = arrayName + "_" + i.ToString(CultureInfo.InvariantCulture); - _choiceArrayName = "choice_" + _arrayName; + _arrayName = string.Create(CultureInfo.InvariantCulture, $"{arrayName}_{i}"); + _choiceArrayName = $"choice_{_arrayName}"; _choiceSource = choiceSource; if (mapping.TypeDesc!.IsArrayLike) @@ -93,13 +93,12 @@ internal Member(XmlSerializationReaderILGen outerClass, string source, string? a _choiceArraySource = outerClass.GetArraySource(mapping.TypeDesc, _choiceArrayName, multiRef); string a = _choiceArrayName; - string c = "c" + a; + string c = $"c{a}"; string choiceTypeFullName = mapping.ChoiceIdentifier.Mapping!.TypeDesc!.CSharpName; - string castString = "(" + choiceTypeFullName + "[])"; + string castString = $"({choiceTypeFullName}[])"; - string init = a + " = " + castString + - "EnsureArrayIndex(" + a + ", " + c + ", " + outerClass.RaCodeGen.GetStringForTypeof(choiceTypeFullName) + ");"; - _choiceArraySource = init + outerClass.RaCodeGen.GetStringForArrayMember(a, c + "++", mapping.ChoiceIdentifier.Mapping.TypeDesc); + string init = $"{a} = {castString}EnsureArrayIndex({a}, {c}, {outerClass.RaCodeGen.GetStringForTypeof(choiceTypeFullName)});"; + _choiceArraySource = init + outerClass.RaCodeGen.GetStringForArrayMember(a, $"{c}++", mapping.ChoiceIdentifier.Mapping.TypeDesc); } else { @@ -460,7 +459,7 @@ private string GenerateLiteralMembersElement(XmlMembersMapping xmlMembersMapping member.ParamsReadSource = $"paramsRead[{i}]"; if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) { - string nameSpecified = mapping.Name + "Specified"; + string nameSpecified = $"{mapping.Name}Specified"; for (int j = 0; j < mappings.Length; j++) { if (mappings[j].Name == nameSpecified) @@ -586,7 +585,7 @@ private string GenerateLiteralMembersElement(XmlMembersMapping xmlMembersMapping } WriteWhileNotLoopStart(); - string unknownNode = "UnknownNode((object)p, " + ExpectedElements(members) + ");"; + string unknownNode = $"UnknownNode((object)p, {ExpectedElements(members)});"; WriteMemberElements(members, unknownNode, unknownNode, anyElement, anyText); ilg.Ldarg(0); @@ -675,7 +674,7 @@ private string GenerateTypeElement(XmlTypeMapping xmlTypeMapping) ilg.Call(XmlSerializationReader_get_Reader); ilg.Call(XmlReader_MoveToContent); ilg.Pop(); - string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");"; + string unknownNode = $"UnknownNode(null, {ExpectedElements(members)});"; WriteMemberElements(members, "throw CreateUnknownNodeException();", unknownNode, element.Any ? members[0] : null, null); ilg.Ldloc(oLoc); // for code compat as compiler does @@ -753,7 +752,7 @@ private void WritePrimitive(TypeMapping mapping, string source) } else { - throw Globals.NotSupported("Unexpected: " + source); + throw Globals.NotSupported($"Unexpected: {source}"); } ilg.Call(methodBuilder); } @@ -799,7 +798,7 @@ private void WritePrimitive(TypeMapping mapping, string source) } else { - throw Globals.NotSupported("Unexpected: " + source); + throw Globals.NotSupported($"Unexpected: {source}"); } } else if (mapping.TypeDesc!.FormatterName == "String") @@ -869,7 +868,7 @@ private void WritePrimitive(TypeMapping mapping, string source) } ToXXX = typeof(XmlSerializationReader).GetMethod( - "To" + mapping.TypeDesc.FormatterName, + $"To{mapping.TypeDesc.FormatterName}", bindingFlags, new Type[] { argType } )!; @@ -877,7 +876,7 @@ private void WritePrimitive(TypeMapping mapping, string source) else { ToXXX = typeof(XmlConvert).GetMethod( - "To" + mapping.TypeDesc.FormatterName, + $"To{mapping.TypeDesc.FormatterName}", CodeGenerator.StaticBindingFlags, new Type[] { argType } )!; @@ -958,9 +957,9 @@ private string WriteHashtable(EnumMapping mapping, string typeName, out MethodBu get_TableName = null; CodeIdentifier.CheckValidIdentifier(typeName); - string? propName = MakeUnique(mapping, typeName + "Values"); + string? propName = MakeUnique(mapping, $"{typeName}Values"); if (propName == null) return CodeIdentifier.GetCSharpName(typeName); - string memberName = MakeUnique(mapping, "_" + propName)!; + string memberName = MakeUnique(mapping, $"_{propName}")!; propName = CodeIdentifier.GetCSharpName(propName); FieldBuilder fieldBuilder = this.typeBuilder.DefineField( @@ -979,7 +978,7 @@ private string WriteHashtable(EnumMapping mapping, string typeName, out MethodBu ilg = new CodeGenerator(this.typeBuilder); ilg.BeginMethod( typeof(Hashtable), - "get_" + propName, + $"get_{propName}", Type.EmptyTypes, Array.Empty(), MethodAttributes.Assembly | MethodAttributes.HideBySig | MethodAttributes.SpecialName); @@ -1570,7 +1569,7 @@ private void WriteLiteralStructMethod(StructMapping structMapping) member.ParamsReadSource = $"paramsRead[{i}]"; member.IsNullable = mapping.TypeDesc!.IsNullable; if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) - member.CheckSpecifiedSource = RaCodeGen.GetStringForMember("o", mapping.Name + "Specified", structMapping.TypeDesc); + member.CheckSpecifiedSource = RaCodeGen.GetStringForMember("o", $"{mapping.Name}Specified", structMapping.TypeDesc); if (mapping.Text != null) anyText = member; if (mapping.Attribute != null && mapping.Attribute.Any) @@ -1687,7 +1686,7 @@ private void WriteLiteralStructMethod(StructMapping structMapping) ilg.Stloc(typeof(int), "state"); } WriteWhileNotLoopStart(); - string unknownNode = "UnknownNode((object)o, " + ExpectedElements(allMembers) + ");"; + string unknownNode = $"UnknownNode((object)o, {ExpectedElements(allMembers)});"; WriteMemberElements(allMembers, unknownNode, unknownNode, anyElement, anyText); MethodInfo XmlReader_MoveToContent = typeof(XmlReader).GetMethod( "MoveToContent", @@ -1770,7 +1769,7 @@ private void WriteXmlNodeEqual(string source, string name, string? ns, bool doAn // Only support Reader and XmlSerializationReaderReader only System.Diagnostics.Debug.Assert(source == "Reader"); MethodInfo XmlSerializationReader_get_Reader = typeof(XmlSerializationReader).GetMethod( - "get_" + source, + $"get_{source}", CodeGenerator.InstanceBindingFlags, Type.EmptyTypes )!; @@ -2039,7 +2038,7 @@ private void WriteAttributes(Member[] members, Member? anyAttribute, string else AttributeAccessor attribute = attributes[i]; if (i > 0) qnames += ", "; - qnames += attribute.IsSpecialXmlNamespace ? XmlReservedNs.NsXml : (attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : "") + ":" + attribute.Name; + qnames += attribute.IsSpecialXmlNamespace ? XmlReservedNs.NsXml : $"{(attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : "")}:{attribute.Name}"; } argTypes.Add(typeof(string)); ilg.Ldstr(qnames); @@ -2167,7 +2166,7 @@ private void WriteMemberBegin(Member[] members) if (member.IsArrayLike) { string a = member.ArrayName; - string c = "c" + a; + string c = $"c{a}"; TypeDesc typeDesc = member.Mapping.TypeDesc!; @@ -2180,11 +2179,11 @@ private void WriteMemberBegin(Member[] members) if (member.Mapping.ChoiceIdentifier != null) { - WriteArrayLocalDecl(member.Mapping.ChoiceIdentifier.Mapping!.TypeDesc!.CSharpName + "[]", + WriteArrayLocalDecl($"{member.Mapping.ChoiceIdentifier.Mapping!.TypeDesc!.CSharpName}[]", member.ChoiceArrayName, "null", member.Mapping.ChoiceIdentifier.Mapping.TypeDesc); ilg.Ldc(0); - ilg.Stloc(typeof(int), "c" + member.ChoiceArrayName); + ilg.Stloc(typeof(int), $"c{member.ChoiceArrayName}"); } } else @@ -2257,7 +2256,7 @@ private string ExpectedElements(Member[] members) if (!firstElement) qnames += ", "; - qnames += ns + ":" + e.Name; + qnames += $"{ns}:{e.Name}"; firstElement = false; } } @@ -2630,26 +2629,24 @@ private string GetArraySource(TypeDesc typeDesc, string arrayName) private string GetArraySource(TypeDesc typeDesc, string arrayName, bool multiRef) { string a = arrayName; - string c = "c" + a; + string c = $"c{a}"; string init = ""; if (multiRef) { - init = "soap = (System.Object[])EnsureArrayIndex(soap, " + c + "+2, typeof(System.Object)); "; + init = $"soap = (System.Object[])EnsureArrayIndex(soap, {c}+2, typeof(System.Object)); "; } if (typeDesc.IsArray) { string arrayTypeFullName = typeDesc.ArrayElementTypeDesc!.CSharpName; - string castString = "(" + arrayTypeFullName + "[])"; - init = init + a + " = " + castString + - "EnsureArrayIndex(" + a + ", " + c + ", " + RaCodeGen.GetStringForTypeof(arrayTypeFullName) + ");"; - string arraySource = RaCodeGen.GetStringForArrayMember(a, c + "++", typeDesc); + init = $"{init}{a} = ({arrayTypeFullName}[])EnsureArrayIndex({a}, {c}, {RaCodeGen.GetStringForTypeof(arrayTypeFullName)});"; + string arraySource = RaCodeGen.GetStringForArrayMember(a, $"{c}++", typeDesc); if (multiRef) { - init = init + " soap[1] = " + a + ";"; - init = init + " if (ReadReference(out soap[" + c + "+2])) " + arraySource + " = null; else "; + init = $"{init} soap[1] = {a};"; + init = $"{init} if (ReadReference(out soap[{c}+2])) {arraySource} = null; else "; } - return init + arraySource; + return $"{init}{arraySource}"; } else { @@ -2681,7 +2678,7 @@ private void WriteMemberEnd(Member[] members, bool soapRefs) Debug.Assert(!soapRefs); string a = member.ArrayName; - string c = "c" + a; + string c = $"c{a}"; MethodInfo XmlSerializationReader_ShrinkArray = typeof(XmlSerializationReader).GetMethod( "ShrinkArray", @@ -2701,7 +2698,7 @@ private void WriteMemberEnd(Member[] members, bool soapRefs) { WriteSourceBegin(member.ChoiceSource!); a = member.ChoiceArrayName; - c = "c" + a; + c = $"c{a}"; ilg.Ldarg(0); ilg.Ldloc(ilg.GetLocal(a)); @@ -2805,7 +2802,7 @@ private void WriteSourceBegin(string source) ilg.Load(ilg.GetVariable(match.Groups["ia"].Value)); return; } - throw Globals.NotSupported("Unexpected: " + source); + throw Globals.NotSupported($"Unexpected: {source}"); } [RequiresUnreferencedCode("calls WriteSourceEnd")] @@ -2891,7 +2888,7 @@ private void WriteSourceEnd(string source, Type elementType, Type stackType) ilg.Stelem(varElementType); return; } - throw Globals.NotSupported("Unexpected: " + source); + throw Globals.NotSupported($"Unexpected: {source}"); } [RequiresUnreferencedCode("calls WriteMemberBegin")] @@ -2973,7 +2970,7 @@ private void WriteArray(string source, string? arrayName, ArrayMapping arrayMapp ilg.Call(XmlReader_ReadStartElement); WriteWhileNotLoopStart(); - string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");"; + string unknownNode = $"UnknownNode(null, {ExpectedElements(members)});"; WriteMemberElements(members, unknownNode, unknownNode, null, null); MethodInfo XmlReader_MoveToContent = typeof(XmlReader).GetMethod( "MoveToContent", @@ -3590,7 +3587,7 @@ private void ILGenElseString(string elseString) ilg.Call(XmlSerializationReader_UnknownNode1); return; } - throw Globals.NotSupported("Unexpected: " + elseString); + throw Globals.NotSupported($"Unexpected: {elseString}"); } private void ILGenParamsReadSource(string paramsReadSource) { @@ -3601,7 +3598,7 @@ private void ILGenParamsReadSource(string paramsReadSource) ilg.LoadArrayElement(ilg.GetLocal("paramsRead"), int.Parse(match.Groups["index"].Value, CultureInfo.InvariantCulture)); return; } - throw Globals.NotSupported("Unexpected: " + paramsReadSource); + throw Globals.NotSupported($"Unexpected: {paramsReadSource}"); } private void ILGenParamsReadSource(string paramsReadSource, bool value) { @@ -3612,7 +3609,7 @@ private void ILGenParamsReadSource(string paramsReadSource, bool value) ilg.StoreArrayElement(ilg.GetLocal("paramsRead"), int.Parse(match.Groups["index"].Value, CultureInfo.InvariantCulture), value); return; } - throw Globals.NotSupported("Unexpected: " + paramsReadSource); + throw Globals.NotSupported($"Unexpected: {paramsReadSource}"); } private void ILGenElementElseString(string elementElseString) { @@ -3633,7 +3630,7 @@ private void ILGenElementElseString(string elementElseString) ILGenElseString(elementElseString); return; } - throw Globals.NotSupported("Unexpected: " + elementElseString); + throw Globals.NotSupported($"Unexpected: {elementElseString}"); } [RequiresUnreferencedCode("calls WriteSourceEnd")] diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs index 7ebc4462dfb7a6..991be5cdf3a0a2 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs @@ -426,7 +426,7 @@ private string GetQualifiedName(string name, string? ns) { return name; } - return prefix + ":" + name; + return $"{prefix}:{name}"; } protected string? FromXmlQualifiedName(XmlQualifiedName? xmlQualifiedName) @@ -850,7 +850,7 @@ protected void WriteReferencingElement(string n, string? ns, object? o, bool isN if (_soap12) _w.WriteAttributeString("ref", Soap12.Encoding, GetId(o, true)); else - _w.WriteAttributeString("href", "#" + GetId(o, true)); + _w.WriteAttributeString("href", $"#{GetId(o, true)}"); _w.WriteEndElement(); } @@ -871,7 +871,7 @@ private string GetId(object o, bool addToReferencesList) string? id = (string?)_references[o]; if (id == null) { - id = _idBase + "id" + (++_nextId).ToString(CultureInfo.InvariantCulture); + id = string.Create(CultureInfo.InvariantCulture, $"{_idBase}id{++_nextId}"); _references.Add(o, id); if (addToReferencesList) _referencesToWrite!.Add(o); } @@ -1272,7 +1272,7 @@ private void WriteArray(string name, string? ns, object o, Type type) } else { - string brackets = arrayLength >= 0 ? "[" + arrayLength + "]" : "[]"; + string brackets = arrayLength >= 0 ? $"[{arrayLength}]" : "[]"; _w.WriteAttributeString("arrayType", Soap.Encoding, GetQualifiedName(typeName, typeNs) + brackets); } IEnumerator e = ((IEnumerable)o).GetEnumerator(); @@ -1535,7 +1535,7 @@ internal static void Add(Assembly a) else if (oldAssembly != a) { //more than one assembly with same name - key = a.FullName + ", " + s_nameToAssemblyMap.Count; + key = $"{a.FullName}, {s_nameToAssemblyMap.Count}"; } if (key != null) { @@ -1610,12 +1610,12 @@ private string WriteTypeInfo(TypeScope scope, TypeDesc typeDesc, Type type) if (elementTypeDesc.UseReflection) { string elementTypeVariable = WriteTypeInfo(scope, elementTypeDesc, scope.GetTypeFromTypeDesc(elementTypeDesc)!); - _writer.WriteLine("static " + typeof(Type).FullName + " " + typeVariable + " = " + elementTypeVariable + ".MakeArrayType();"); + _writer.WriteLine($"static {typeof(Type).FullName} {typeVariable} = {elementTypeVariable}.MakeArrayType();"); } else { string assemblyVariable = WriteAssemblyInfo(type); - _writer.Write("static " + typeof(Type).FullName + " " + typeVariable + " = " + assemblyVariable + ".GetType("); + _writer.Write($"static {typeof(Type).FullName} {typeVariable} = {assemblyVariable}.GetType("); WriteQuotedCSharpString(type.FullName); _writer.WriteLine(");"); } @@ -1628,12 +1628,12 @@ private string WriteTypeInfo(TypeScope scope, TypeDesc typeDesc, Type type) if (parameterType != null) { string parameterTypeVariable = WriteTypeInfo(scope, scope.GetTypeDesc(parameterType), parameterType); - _writer.WriteLine("static " + typeof(Type).FullName + " " + typeVariable + " = typeof(System.Nullable<>).MakeGenericType(new " + typeof(Type).FullName + "[] {" + parameterTypeVariable + "});"); + _writer.WriteLine($"static {typeof(Type).FullName} {typeVariable} = typeof(System.Nullable<>).MakeGenericType(new {typeof(Type).FullName}[] {{{parameterTypeVariable}}});"); } else { string assemblyVariable = WriteAssemblyInfo(type); - _writer.Write("static " + typeof(Type).FullName + " " + typeVariable + " = " + assemblyVariable + ".GetType("); + _writer.Write($"static {typeof(Type).FullName} {typeVariable} = {assemblyVariable}.GetType("); WriteQuotedCSharpString(type.FullName); _writer.WriteLine(");"); } @@ -1682,12 +1682,12 @@ private void WriteMappingInfo(TypeMapping mapping, string typeVariable, string memberVariable = WriteMemberInfo(type, typeFullName, typeVariable, member.Name); if (member.CheckShouldPersist) { - string memberName = "ShouldSerialize" + member.Name; + string memberName = $"ShouldSerialize{member.Name}"; memberVariable = WriteMethodInfo(typeFullName, typeVariable, memberName, false); } if (member.CheckSpecified != SpecifiedAccessor.None) { - string memberName = member.Name + "Specified"; + string memberName = $"{member.Name}Specified"; memberVariable = WriteMemberInfo(type, typeFullName, typeVariable, memberName); } if (member.ChoiceIdentifier != null) @@ -1740,7 +1740,7 @@ private string WriteAssemblyInfo(Type type) string assemblyName = (iComma > -1) ? assemblyFullName.Substring(0, iComma) : assemblyFullName; assemblyVariable = GenerateVariableName("assembly", assemblyName); //writer.WriteLine("static "+ typeof(Assembly).FullName+" "+assemblyVariable+" = "+typeof(Assembly).FullName+".Load("); - _writer.Write("static " + typeof(Assembly).FullName + " " + assemblyVariable + " = " + "ResolveDynamicAssembly("); + _writer.Write($"static {typeof(Assembly).FullName} {assemblyVariable} = ResolveDynamicAssembly("); WriteQuotedCSharpString(DynamicAssemblies.GetName(type.Assembly)/*assemblyFullName*/); _writer.WriteLine(");"); _reflectionVariables.Add(assemblyFullName, assemblyVariable); @@ -1757,19 +1757,19 @@ private string WriteMemberInfo( if (memberInfos[i] is PropertyInfo) { string propVariable = GenerateVariableName("prop", memberName); - _writer.Write("static XSPropInfo " + propVariable + " = new XSPropInfo(" + typeVariable + ", "); + _writer.Write($"static XSPropInfo {propVariable} = new XSPropInfo({typeVariable}, "); WriteQuotedCSharpString(memberName); _writer.WriteLine(");"); - _reflectionVariables.Add(memberName + ":" + escapedName, propVariable); + _reflectionVariables.Add($"{memberName}:{escapedName}", propVariable); return propVariable; } else if (memberInfos[i] is FieldInfo) { string fieldVariable = GenerateVariableName("field", memberName); - _writer.Write("static XSFieldInfo " + fieldVariable + " = new XSFieldInfo(" + typeVariable + ", "); + _writer.Write($"static XSFieldInfo {fieldVariable} = new XSFieldInfo({typeVariable}, "); WriteQuotedCSharpString(memberName); _writer.WriteLine(");"); - _reflectionVariables.Add(memberName + ":" + escapedName, fieldVariable); + _reflectionVariables.Add($"{memberName}:{escapedName}", fieldVariable); return fieldVariable; } } @@ -1779,7 +1779,7 @@ private string WriteMemberInfo( private string WriteMethodInfo(string escapedName, string typeVariable, string memberName, bool isNonPublic, params string[] paramTypes) { string methodVariable = GenerateVariableName("method", memberName); - _writer.Write("static " + typeof(MethodInfo).FullName + " " + methodVariable + " = " + typeVariable + ".GetMethod("); + _writer.Write($"static {typeof(MethodInfo).FullName} {methodVariable} = {typeVariable}.GetMethod("); WriteQuotedCSharpString(memberName); _writer.Write(", "); @@ -1798,7 +1798,7 @@ private string WriteMethodInfo(string escapedName, string typeVariable, string m _writer.Write(".NonPublic"); } _writer.Write(", null, "); - _writer.Write("new " + typeof(Type).FullName + "[] { "); + _writer.Write($"new {typeof(Type).FullName}[] {{ "); for (int i = 0; i < paramTypes.Length; i++) { _writer.Write(paramTypes[i]); @@ -1806,7 +1806,7 @@ private string WriteMethodInfo(string escapedName, string typeVariable, string m _writer.Write(", "); } _writer.WriteLine("}, null);"); - _reflectionVariables.Add(memberName + ":" + escapedName, methodVariable); + _reflectionVariables.Add($"{memberName}:{escapedName}", methodVariable); return methodVariable; } @@ -1827,15 +1827,14 @@ private string WriteDefaultIndexerInit( _writer.Write(",new "); _writer.Write(typeof(Type[]).FullName); _writer.WriteLine("{typeof(int)}));"); - _reflectionVariables.Add(arrayMemberKey + ":" + escapedName, itemVariable); + _reflectionVariables.Add($"{arrayMemberKey}:{escapedName}", itemVariable); return itemVariable; } private string GenerateVariableName(string prefix, string fullName) { ++_nextReflectionVariableNumber; - return prefix + _nextReflectionVariableNumber + "_" + - CodeIdentifier.MakeValidInternal(fullName.Replace('.', '_')); + return $"{prefix}{_nextReflectionVariableNumber}_{CodeIdentifier.MakeValidInternal(fullName.Replace('.', '_'))}"; } internal string? GetReflectionVariable(string typeFullName, string? memberName) { @@ -1843,7 +1842,7 @@ private string GenerateVariableName(string prefix, string fullName) if (memberName == null) key = typeFullName; else - key = memberName + ":" + typeFullName; + key = $"{memberName}:{typeFullName}"; return (string?)_reflectionVariables[key]; } @@ -1883,7 +1882,7 @@ internal string GetStringForEnumCompare(EnumMapping mapping, string memberName, if (!useReflection) { CodeIdentifier.CheckValidIdentifier(memberName); - return mapping.TypeDesc!.CSharpName + ".@" + memberName; + return $"{mapping.TypeDesc!.CSharpName}.@{memberName}"; } string memberAccess = GetStringForEnumMember(mapping.TypeDesc!.CSharpName, memberName, useReflection); return GetStringForEnumLongValue(memberAccess, useReflection); @@ -1891,8 +1890,8 @@ internal string GetStringForEnumCompare(EnumMapping mapping, string memberName, internal string GetStringForEnumLongValue(string variable, bool useReflection) { if (useReflection) - return typeof(Convert).FullName + ".ToInt64(" + variable + ")"; - return "((" + typeof(long).FullName + ")" + variable + ")"; + return $"{typeof(Convert).FullName}.ToInt64({variable})"; + return $"(({typeof(long).FullName}){variable})"; } internal string GetStringForTypeof(string typeFullName, bool useReflection) @@ -1903,30 +1902,30 @@ internal string GetStringForTypeof(string typeFullName, bool useReflection) } else { - return "typeof(" + typeFullName + ")"; + return $"typeof({typeFullName})"; } } internal string GetStringForMember(string obj, string memberName, TypeDesc typeDesc) { if (!typeDesc.UseReflection) - return obj + ".@" + memberName; + return $"{obj}.@{memberName}"; while (typeDesc != null) { string typeFullName = typeDesc.CSharpName; string? memberInfoName = GetReflectionVariable(typeFullName, memberName); if (memberInfoName != null) - return memberInfoName + "[" + obj + "]"; + return $"{memberInfoName}[{obj}]"; // member may be part of the basetype typeDesc = typeDesc.BaseTypeDesc!; if (typeDesc != null && !typeDesc.UseReflection) - return "((" + typeDesc.CSharpName + ")" + obj + ").@" + memberName; + return $"(({typeDesc.CSharpName}){obj}).@{memberName}"; } //throw GetReflectionVariableException(saveTypeDesc.CSharpName,memberName); // NOTE, sowmys:Must never happen. If it does let the code // gen continue to help debugging what's gone wrong. // Eventually the compilation will fail. - return "[" + obj + "]"; + return $"[{obj}]"; } /* Exception GetReflectionVariableException(string typeFullName, string memberName){ @@ -1946,29 +1945,29 @@ Exception GetReflectionVariableException(string typeFullName, string memberName) internal string GetStringForEnumMember(string typeFullName, string memberName, bool useReflection) { if (!useReflection) - return typeFullName + ".@" + memberName; + return $"{typeFullName}.@{memberName}"; string? memberInfoName = GetReflectionVariable(typeFullName, memberName); - return memberInfoName + "[null]"; + return $"{memberInfoName}[null]"; } internal string GetStringForArrayMember(string arrayName, string subscript, TypeDesc arrayTypeDesc) { if (!arrayTypeDesc.UseReflection) { - return arrayName + "[" + subscript + "]"; + return $"{arrayName}[{subscript}]"; } string typeFullName = arrayTypeDesc.IsCollection ? arrayTypeDesc.CSharpName : typeof(Array).FullName!; string? arrayInfo = GetReflectionVariable(typeFullName, arrayMemberKey); - return arrayInfo + "[" + arrayName + ", " + subscript + "]"; + return $"{arrayInfo}[{arrayName}, {subscript}]"; } internal string GetStringForMethod(string obj, string typeFullName, string memberName, bool useReflection) { if (!useReflection) - return obj + "." + memberName + "("; + return $"{obj}.{memberName}("; string? memberInfoName = GetReflectionVariable(typeFullName, memberName); - return memberInfoName + ".Invoke(" + obj + ", new object[]{"; + return $"{memberInfoName}.Invoke({obj}, new object[]{{"; } internal string GetStringForCreateInstance(string escapedTypeName, bool useReflection, bool ctorInaccessible, bool cast) { @@ -1978,7 +1977,7 @@ internal string GetStringForCreateInstance(string escapedTypeName, bool useRefle internal string GetStringForCreateInstance(string escapedTypeName, bool useReflection, bool ctorInaccessible, bool cast, string arg) { if (!useReflection && !ctorInaccessible) - return "new " + escapedTypeName + "(" + arg + ")"; + return $"new {escapedTypeName}({arg})"; return GetStringForCreateInstance(GetStringForTypeof(escapedTypeName, useReflection), cast && !useReflection ? escapedTypeName : null, ctorInaccessible, arg); } @@ -2035,7 +2034,7 @@ internal void WriteLocalDecl(string typeFullName, string variableName, string in _writer.Write(" = "); if (!useReflection && initValue != "null") { - _writer.Write("(" + typeFullName + ")"); + _writer.Write($"({typeFullName})"); } _writer.Write(initValue); } @@ -2084,7 +2083,7 @@ internal void WriteArrayLocalDecl(string typeName, string variableName, string? { _writer.Write(" = "); if (initValue != "null") - _writer.Write("(" + typeName + ")"); + _writer.Write($"({typeName})"); _writer.Write(initValue); } _writer.WriteLine(";"); @@ -2124,7 +2123,7 @@ internal void WriteArrayTypeCompare(string variable, string escapedTypeName, str _writer.Write(variable); _writer.Write(".IsArray "); _writer.Write(" && "); - WriteTypeCompare(variable + ".GetElementType()", elementTypeName, useReflection); + WriteTypeCompare($"{variable}.GetElementType()", elementTypeName, useReflection); } internal static void WriteQuotedCSharpString(IndentedWriter writer, string? value) @@ -2636,7 +2635,7 @@ private string GenerateMembersElement(XmlMembersMapping xmlMembersMapping) int specifiedPosition = 0; if (member.CheckSpecified != SpecifiedAccessor.None) { - string memberNameSpecified = member.Name + "Specified"; + string memberNameSpecified = $"{member.Name}Specified"; for (int j = 0; j < mapping.Members.Length; j++) { if (mapping.Members[j].Name == memberNameSpecified) @@ -2689,7 +2688,7 @@ private string GenerateMembersElement(XmlMembersMapping xmlMembersMapping) int specifiedPosition = 0; if (member.CheckSpecified != SpecifiedAccessor.None) { - string memberNameSpecified = member.Name + "Specified"; + string memberNameSpecified = $"{member.Name}Specified"; for (int j = 0; j < mapping.Members.Length; j++) { @@ -2718,7 +2717,7 @@ private string GenerateMembersElement(XmlMembersMapping xmlMembersMapping) Writer.Indent++; } - string source = "p[" + index + "]"; + string source = $"p[{index}]"; string? enumSource = null; if (member.ChoiceIdentifier != null) { @@ -2835,7 +2834,7 @@ private string GenerateTypeElement(XmlTypeMapping xmlTypeMapping) private string NextMethodName(string name) { - return "Write" + (++NextMethodNumber).ToString(null, NumberFormatInfo.InvariantInfo) + "_" + CodeIdentifier.MakeValidInternal(name); + return string.Create(CultureInfo.InvariantCulture, $"Write{++NextMethodNumber}_{CodeIdentifier.MakeValidInternal(name)}"); } private void WriteEnumMethod(EnumMapping mapping) @@ -2866,7 +2865,7 @@ private void WriteEnumMethod(EnumMapping mapping) { Hashtable values = new Hashtable(); if (mapping.TypeDesc.UseReflection) - Writer.WriteLine("switch (" + RaCodeGen.GetStringForEnumLongValue("v", mapping.TypeDesc.UseReflection) + " ){"); + Writer.WriteLine($"switch ({RaCodeGen.GetStringForEnumLongValue("v", mapping.TypeDesc.UseReflection)} ){{"); else Writer.WriteLine("switch (v) {"); Writer.Indent++; @@ -2969,7 +2968,7 @@ private void WriteDerivedTypes(StructMapping mapping) Writer.Write(methodName); Writer.Write("(n, ns,"); - if (!derived.TypeDesc.UseReflection) Writer.Write("(" + fullTypeName + ")"); + if (!derived.TypeDesc.UseReflection) Writer.Write($"({fullTypeName})"); Writer.Write("o"); if (derived.TypeDesc.IsNullable) Writer.Write(", isNullable"); @@ -3014,7 +3013,7 @@ private void WriteEnumAndArrayTypes() Writer.Write("Writer.WriteString("); Writer.Write(methodName); Writer.Write("("); - if (!mapping.TypeDesc.UseReflection) Writer.Write("(" + fullTypeName + ")"); + if (!mapping.TypeDesc.UseReflection) Writer.Write($"({fullTypeName})"); Writer.WriteLine("o));"); Writer.WriteLine("Writer.WriteEndElement();"); Writer.WriteLine("return;"); @@ -3135,7 +3134,7 @@ private void WriteStructMethod(StructMapping mapping) xmlnsSource = RaCodeGen.GetStringForMember("o", member.Name, mapping.TypeDesc); if (mapping.TypeDesc.UseReflection) { - xmlnsSource = "((" + member.TypeDesc!.CSharpName + ")" + xmlnsSource + ")"; + xmlnsSource = $"(({member.TypeDesc!.CSharpName}){xmlnsSource})"; } } @@ -3170,8 +3169,8 @@ private void WriteStructMethod(StructMapping mapping) if (m.CheckShouldPersist) { Writer.Write("if ("); - string methodInvoke = RaCodeGen.GetStringForMethodInvoke("o", fullTypeName, "ShouldSerialize" + m.Name, mapping.TypeDesc.UseReflection); - if (mapping.TypeDesc.UseReflection) methodInvoke = "((" + typeof(bool).FullName + ")" + methodInvoke + ")"; + string methodInvoke = RaCodeGen.GetStringForMethodInvoke("o", fullTypeName, $"ShouldSerialize{m.Name}", mapping.TypeDesc.UseReflection); + if (mapping.TypeDesc.UseReflection) methodInvoke = $"(({typeof(bool).FullName}){methodInvoke})"; Writer.Write(methodInvoke); Writer.WriteLine(") {"); Writer.Indent++; @@ -3179,8 +3178,8 @@ private void WriteStructMethod(StructMapping mapping) if (m.CheckSpecified != SpecifiedAccessor.None) { Writer.Write("if ("); - string memberGet = RaCodeGen.GetStringForMember("o", m.Name + "Specified", mapping.TypeDesc); - if (mapping.TypeDesc.UseReflection) memberGet = "((" + typeof(bool).FullName + ")" + memberGet + ")"; + string memberGet = RaCodeGen.GetStringForMember("o", $"{m.Name}Specified", mapping.TypeDesc); + if (mapping.TypeDesc.UseReflection) memberGet = $"(({typeof(bool).FullName}){memberGet})"; Writer.Write(memberGet); Writer.WriteLine(") {"); Writer.Indent++; @@ -3211,8 +3210,8 @@ private void WriteStructMethod(StructMapping mapping) if (checkShouldPersist) { Writer.Write("if ("); - string methodInvoke = RaCodeGen.GetStringForMethodInvoke("o", fullTypeName, "ShouldSerialize" + m.Name, mapping.TypeDesc.UseReflection); - if (mapping.TypeDesc.UseReflection) methodInvoke = "((" + typeof(bool).FullName + ")" + methodInvoke + ")"; + string methodInvoke = RaCodeGen.GetStringForMethodInvoke("o", fullTypeName, $"ShouldSerialize{m.Name}", mapping.TypeDesc.UseReflection); + if (mapping.TypeDesc.UseReflection) methodInvoke = $"(({typeof(bool).FullName}){methodInvoke})"; Writer.Write(methodInvoke); Writer.WriteLine(") {"); Writer.Indent++; @@ -3220,8 +3219,8 @@ private void WriteStructMethod(StructMapping mapping) if (m.CheckSpecified != SpecifiedAccessor.None) { Writer.Write("if ("); - string memberGet = RaCodeGen.GetStringForMember("o", m.Name + "Specified", mapping.TypeDesc); - if (mapping.TypeDesc.UseReflection) memberGet = "((" + typeof(bool).FullName + ")" + memberGet + ")"; + string memberGet = RaCodeGen.GetStringForMember("o", $"{m.Name}Specified", mapping.TypeDesc); + if (mapping.TypeDesc.UseReflection) memberGet = $"(({typeof(bool).FullName}){memberGet})"; Writer.Write(memberGet); Writer.WriteLine(") {"); Writer.Indent++; @@ -3456,7 +3455,7 @@ private void WriteAttribute(string source, AttributeAccessor attribute, string p else { TypeDesc typeDesc = attribute.Mapping!.TypeDesc!; - if (!typeDesc.UseReflection) source = "((" + typeDesc.CSharpName + ")" + source + ")"; + if (!typeDesc.UseReflection) source = $"(({typeDesc.CSharpName}){source})"; WritePrimitive("WriteAttribute", attribute.Name, attribute.Form == XmlSchemaForm.Qualified ? attribute.Namespace : "", attribute.Default, source, attribute.Mapping, false, false, false); } } @@ -3488,7 +3487,7 @@ private void WriteArray(string source, string? choiceSource, ElementAccessor[] e if (choice != null) { string choiceFullName = choice.Mapping!.TypeDesc!.CSharpName; - WriteArrayLocalDecl(choiceFullName + "[]", "c", choiceSource, choice.Mapping.TypeDesc); + WriteArrayLocalDecl($"{choiceFullName}[]", "c", choiceSource, choice.Mapping.TypeDesc); // write check for the choice identifier array Writer.WriteLine("if (c == null || c.Length < a.Length) {"); Writer.Indent++; @@ -3565,8 +3564,8 @@ private void WriteArrayItems(ElementAccessor[] elements, TextAccessor? text, Cho Writer.WriteLine("while (e.MoveNext()) {"); Writer.Indent++; string arrayTypeFullName = arrayElementTypeDesc.CSharpName; - WriteLocalDecl(arrayTypeFullName, arrayName + "i", "e.Current", arrayElementTypeDesc.UseReflection); - WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, true); + WriteLocalDecl(arrayTypeFullName, $"{arrayName}i", "e.Current", arrayElementTypeDesc.UseReflection); + WriteElements($"{arrayName}i", $"{choiceName}i", elements, text, choice, $"{arrayName}a", true, true); } else { @@ -3596,17 +3595,17 @@ private void WriteArrayItems(ElementAccessor[] elements, TextAccessor? text, Cho if (count > 1) { string arrayTypeFullName = arrayElementTypeDesc.CSharpName; - WriteLocalDecl(arrayTypeFullName, arrayName + "i", RaCodeGen.GetStringForArrayMember(arrayName, "i" + arrayName, arrayTypeDesc), arrayElementTypeDesc.UseReflection); + WriteLocalDecl(arrayTypeFullName, $"{arrayName}i", RaCodeGen.GetStringForArrayMember(arrayName, $"i{arrayName}", arrayTypeDesc), arrayElementTypeDesc.UseReflection); if (choice != null) { string choiceFullName = choice.Mapping!.TypeDesc!.CSharpName; - WriteLocalDecl(choiceFullName, choiceName + "i", RaCodeGen.GetStringForArrayMember(choiceName!, "i" + arrayName, choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.UseReflection); + WriteLocalDecl(choiceFullName, $"{choiceName}i", RaCodeGen.GetStringForArrayMember(choiceName!, $"i{arrayName}", choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.UseReflection); } - WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable); + WriteElements($"{arrayName}i", $"{choiceName}i", elements, text, choice, $"{arrayName}a", true, arrayElementTypeDesc.IsNullable); } else { - WriteElements(RaCodeGen.GetStringForArrayMember(arrayName, "i" + arrayName, arrayTypeDesc), elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable); + WriteElements(RaCodeGen.GetStringForArrayMember(arrayName, $"i{arrayName}", arrayTypeDesc), elements, text, choice, $"{arrayName}a", true, arrayElementTypeDesc.IsNullable); } } Writer.Indent--; @@ -3627,7 +3626,7 @@ private void WriteElements(string source, string? enumSource, ElementAccessor[] { TypeDesc td = elements[0].IsUnbounded ? elements[0].Mapping!.TypeDesc!.CreateArrayTypeDesc() : elements[0].Mapping!.TypeDesc!; if (!elements[0].Any && !elements[0].Mapping!.TypeDesc!.UseReflection && !elements[0].Mapping!.TypeDesc!.IsOptionalValue) - source = "((" + td.CSharpName + ")" + source + ")"; + source = $"(({td.CSharpName}){source})"; WriteElement(source, elements[0], arrayName, writeAccessors); } else @@ -3663,7 +3662,7 @@ private void WriteElements(string source, string? enumSource, ElementAccessor[] bool useReflection = element.Mapping!.TypeDesc!.UseReflection; string fullTypeName = element.Mapping.TypeDesc.CSharpName; bool enumUseReflection = choice.Mapping!.TypeDesc!.UseReflection; - string enumFullName = (enumUseReflection ? "" : enumTypeName + ".@") + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping, enumUseReflection); + string enumFullName = (enumUseReflection ? "" : $"{enumTypeName}.@") + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping, enumUseReflection); if (wroteFirstIf) Writer.Write("else "); else wroteFirstIf = true; @@ -3684,7 +3683,7 @@ private void WriteElements(string source, string? enumSource, ElementAccessor[] string castedSource = source; if (!useReflection) - castedSource = "((" + fullTypeName + ")" + source + ")"; + castedSource = $"(({fullTypeName}){source})"; WriteElement(element.Any ? source : castedSource, element, arrayName, writeAccessors); Writer.Indent--; Writer.WriteLine("}"); @@ -3702,7 +3701,7 @@ private void WriteElements(string source, string? enumSource, ElementAccessor[] Writer.Indent++; string castedSource = source; if (!useReflection) - castedSource = "((" + fullTypeName + ")" + source + ")"; + castedSource = $"(({fullTypeName}){source})"; WriteElement(element.Any ? source : castedSource, element, arrayName, writeAccessors); Writer.Indent--; Writer.WriteLine("}"); @@ -3739,7 +3738,7 @@ private void WriteElements(string source, string? enumSource, ElementAccessor[] if (choice != null) { bool enumUseReflection = choice.Mapping!.TypeDesc!.UseReflection; - enumFullName = (enumUseReflection ? "" : enumTypeName + ".@") + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping, enumUseReflection); + enumFullName = (enumUseReflection ? "" : $"{enumTypeName}.@") + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping, enumUseReflection); Writer.Write("if ("); Writer.Write(enumUseReflection ? RaCodeGen.GetStringForEnumLongValue(enumSource!, enumUseReflection) : enumSource); Writer.Write(" == "); @@ -3815,7 +3814,7 @@ private void WriteElements(string source, string? enumSource, ElementAccessor[] Writer.Indent++; string castedSource = source; if (!useReflection) - castedSource = "((" + fullTypeName + ")" + source + ")"; + castedSource = $"(({fullTypeName}){source})"; WriteText(castedSource, text); Writer.Indent--; Writer.WriteLine("}"); @@ -3824,7 +3823,7 @@ private void WriteElements(string source, string? enumSource, ElementAccessor[] { string castedSource = source; if (!useReflection) - castedSource = "((" + fullTypeName + ")" + source + ")"; + castedSource = $"(({fullTypeName}){source})"; WriteText(castedSource, text); } } @@ -3899,7 +3898,7 @@ private void WriteElement(string source, ElementAccessor element, string arrayNa string fullTypeName = element.Mapping.TypeDesc!.BaseTypeDesc!.CSharpName; string castedSource = source; if (!element.Mapping.TypeDesc.BaseTypeDesc.UseReflection) - castedSource = "((" + fullTypeName + ")" + source + ")"; + castedSource = $"(({fullTypeName}){source})"; ElementAccessor e = element.Clone(); e.Mapping = ((NullableMapping)element.Mapping).BaseMapping; WriteElement(e.Any ? source : castedSource, e, arrayName, writeAccessor); @@ -3942,8 +3941,8 @@ private void WriteElement(string source, ElementAccessor element, string arrayNa { TypeDesc td = mapping.TypeDesc!.CreateArrayTypeDesc(); string fullTypeName = td.CSharpName; - string elementArrayName = "el" + arrayName; - string arrayIndex = "c" + elementArrayName; + string elementArrayName = $"el{arrayName}"; + string arrayIndex = $"c{elementArrayName}"; Writer.WriteLine("{"); Writer.Indent++; WriteArrayLocalDecl(fullTypeName, elementArrayName, source, mapping.TypeDesc); @@ -3988,7 +3987,7 @@ private void WriteElement(string source, ElementAccessor element, string arrayNa Writer.Indent++; element.IsUnbounded = false; - WriteElement(elementArrayName + "[" + arrayIndex + "]", element, arrayName, writeAccessor); + WriteElement($"{elementArrayName}[{arrayIndex}]", element, arrayName, writeAccessor); element.IsUnbounded = true; Writer.Indent--; @@ -4469,7 +4468,7 @@ private string FindChoiceEnumValue(ElementAccessor element, EnumMapping choiceMa throw new InvalidOperationException(SR.Format(SR.XmlChoiceMissingAnyValue, choiceMapping.TypeDesc!.FullName)); } // Type {0} is missing value for '{1}'. - throw new InvalidOperationException(SR.Format(SR.XmlChoiceMissingValue, choiceMapping.TypeDesc!.FullName, element.Namespace + ":" + element.Name, element.Name, element.Namespace)); + throw new InvalidOperationException(SR.Format(SR.XmlChoiceMissingValue, choiceMapping.TypeDesc!.FullName, $"{element.Namespace}:{element.Name}", element.Name, element.Namespace)); } if (!useReflection) CodeIdentifier.CheckValidIdentifier(enumValue); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriterILGen.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriterILGen.cs index 1bf9b7069b16ad..006d9512f15557 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriterILGen.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriterILGen.cs @@ -189,7 +189,7 @@ private void WritePrimitiveValue(TypeDesc typeDesc, SourceInfo source, out Type ilg.Ldarg(0); } MethodInfo FromXXX = typeof(XmlSerializationWriter).GetMethod( - "From" + typeDesc.FormatterName, + $"From{typeDesc.FormatterName}", bindingFlags, new Type[] { typeDesc.Type! } )!; @@ -428,7 +428,7 @@ private string GenerateMembersElement(XmlMembersMapping xmlMembersMapping) int specifiedPosition = 0; if (member.CheckSpecified != SpecifiedAccessor.None) { - string memberNameSpecified = member.Name + "Specified"; + string memberNameSpecified = $"{member.Name}Specified"; for (int j = 0; j < mapping.Members.Length; j++) { if (mapping.Members[j].Name == memberNameSpecified) @@ -483,7 +483,7 @@ private string GenerateMembersElement(XmlMembersMapping xmlMembersMapping) int specifiedPosition = 0; if (member.CheckSpecified != SpecifiedAccessor.None) { - string memberNameSpecified = member.Name + "Specified"; + string memberNameSpecified = $"{member.Name}Specified"; for (int j = 0; j < mapping.Members.Length; j++) { @@ -605,7 +605,7 @@ private string GenerateTypeElement(XmlTypeMapping xmlTypeMapping) private string NextMethodName(string name) { - return "Write" + (++NextMethodNumber).ToString(null, NumberFormatInfo.InvariantInfo) + "_" + CodeIdentifier.MakeValidInternal(name); + return string.Create(CultureInfo.InvariantCulture, $"Write{++NextMethodNumber}_{CodeIdentifier.MakeValidInternal(name)}"); } private void WriteEnumMethod(EnumMapping mapping) @@ -1096,7 +1096,7 @@ private void WriteStructMethod(StructMapping mapping) } if (m.CheckSpecified != SpecifiedAccessor.None) { - string memberGet = RaCodeGen.GetStringForMember("o", m.Name + "Specified", mapping.TypeDesc); + string memberGet = RaCodeGen.GetStringForMember("o", $"{m.Name}Specified", mapping.TypeDesc); ILGenLoad(memberGet); ilg.If(); } @@ -1129,7 +1129,7 @@ private void WriteStructMethod(StructMapping mapping) } if (m.CheckSpecified != SpecifiedAccessor.None) { - string memberGet = RaCodeGen.GetStringForMember("o", m.Name + "Specified", mapping.TypeDesc); + string memberGet = RaCodeGen.GetStringForMember("o", $"{m.Name}Specified", mapping.TypeDesc); ILGenLoad(memberGet); ilg.If(); } @@ -1172,8 +1172,8 @@ private void WriteMember(SourceInfo source, AttributeAccessor attribute, TypeDes if (memberTypeDesc.IsAbstract) return; if (memberTypeDesc.IsArrayLike) { - string aVar = "a" + memberTypeDesc.Name; - string aiVar = "ai" + memberTypeDesc.Name; + string aVar = $"a{memberTypeDesc.Name}"; + string aiVar = $"ai{memberTypeDesc.Name}"; string iVar = "i"; string fullTypeName = memberTypeDesc.CSharpName; ilg.EnterScope(); @@ -1429,7 +1429,7 @@ private void WriteMember(SourceInfo source, string? choiceSource, ElementAccesso WriteArray(source, choiceSource, elements, text, choice, memberTypeDesc); else // NOTE: Use different variable name to work around reuse same variable name in different scope - WriteElements(source, choiceSource, elements, text, choice, "a" + memberTypeDesc.Name, writeAccessors, memberTypeDesc.IsNullable); + WriteElements(source, choiceSource, elements, text, choice, $"a{memberTypeDesc.Name}", writeAccessors, memberTypeDesc.IsNullable); } [RequiresUnreferencedCode("calls WriteArrayItems")] @@ -1437,7 +1437,7 @@ private void WriteArray(SourceInfo source, string? choiceSource, ElementAccessor { if (elements.Length == 0 && text == null) return; string arrayTypeName = arrayTypeDesc.CSharpName; - string aName = "a" + arrayTypeDesc.Name; + string aName = $"a{arrayTypeDesc.Name}"; ilg.EnterScope(); WriteArrayLocalDecl(arrayTypeName, aName, source, arrayTypeDesc); LocalBuilder aLoc = ilg.GetLocal(aName); @@ -1453,8 +1453,8 @@ private void WriteArray(SourceInfo source, string? choiceSource, ElementAccessor { string choiceFullName = choice.Mapping!.TypeDesc!.CSharpName; SourceInfo choiceSourceInfo = new SourceInfo(choiceSource!, null, choice.MemberInfo, null, ilg); - cName = "c" + choice.Mapping.TypeDesc.Name; - WriteArrayLocalDecl(choiceFullName + "[]", cName, choiceSourceInfo, choice.Mapping.TypeDesc); + cName = $"c{choice.Mapping.TypeDesc.Name}"; + WriteArrayLocalDecl($"{choiceFullName}[]", cName, choiceSourceInfo, choice.Mapping.TypeDesc); // write check for the choice identifier array Label labelEnd = ilg.DefineLabel(); Label labelTrue = ilg.DefineLabel(); @@ -1541,10 +1541,10 @@ private void WriteArrayItems(ElementAccessor[] elements, TextAccessor? text, Cho ilg.Load(null); ilg.If(Cmp.NotEqualTo); ilg.WhileBegin(); - string arrayNamePlusA = (arrayName).Replace(arrayTypeDesc.Name, "") + "a" + arrayElementTypeDesc.Name; - string arrayNamePlusI = (arrayName).Replace(arrayTypeDesc.Name, "") + "i" + arrayElementTypeDesc.Name; + string arrayNamePlusA = $"{(arrayName).Replace(arrayTypeDesc.Name, "")}a{arrayElementTypeDesc.Name}"; + string arrayNamePlusI = $"{(arrayName).Replace(arrayTypeDesc.Name, "")}i{arrayElementTypeDesc.Name}"; WriteLocalDecl(arrayNamePlusI, "e.Current", arrayElementTypeDesc.Type!); - WriteElements(new SourceInfo(arrayNamePlusI, null, null, arrayElementTypeDesc.Type, ilg), choiceName + "i", elements, text, choice, arrayNamePlusA, true, true); + WriteElements(new SourceInfo(arrayNamePlusI, null, null, arrayElementTypeDesc.Type, ilg), $"{choiceName}i", elements, text, choice, arrayNamePlusA, true, true); ilg.WhileBeginCondition(); // while (e.MoveNext()) MethodInfo IEnumerator_MoveNext = typeof(IEnumerator).GetMethod( @@ -1561,9 +1561,9 @@ private void WriteArrayItems(ElementAccessor[] elements, TextAccessor? text, Cho else { // Filter out type specific for index (code match reusing local). - string iPlusArrayName = "i" + (arrayName).Replace(arrayTypeDesc.Name, ""); - string arrayNamePlusA = (arrayName).Replace(arrayTypeDesc.Name, "") + "a" + arrayElementTypeDesc.Name; - string arrayNamePlusI = (arrayName).Replace(arrayTypeDesc.Name, "") + "i" + arrayElementTypeDesc.Name; + string iPlusArrayName = $"i{(arrayName).Replace(arrayTypeDesc.Name, "")}"; + string arrayNamePlusA = $"{(arrayName).Replace(arrayTypeDesc.Name, "")}a{arrayElementTypeDesc.Name}"; + string arrayNamePlusI = $"{(arrayName).Replace(arrayTypeDesc.Name, "")}i{arrayElementTypeDesc.Name}"; LocalBuilder localI = ilg.DeclareOrGetLocal(typeof(int), iPlusArrayName); ilg.For(localI, 0, ilg.GetLocal(arrayName)); int count = elements.Length + (text == null ? 0 : 1); @@ -1572,9 +1572,9 @@ private void WriteArrayItems(ElementAccessor[] elements, TextAccessor? text, Cho WriteLocalDecl(arrayNamePlusI, RaCodeGen.GetStringForArrayMember(arrayName, iPlusArrayName, arrayTypeDesc), arrayElementTypeDesc.Type!); if (choice != null) { - WriteLocalDecl(choiceName + "i", RaCodeGen.GetStringForArrayMember(choiceName, iPlusArrayName, choice.Mapping!.TypeDesc!), choice.Mapping.TypeDesc!.Type!); + WriteLocalDecl($"{choiceName}i", RaCodeGen.GetStringForArrayMember(choiceName, iPlusArrayName, choice.Mapping!.TypeDesc!), choice.Mapping.TypeDesc!.Type!); } - WriteElements(new SourceInfo(arrayNamePlusI, null, null, arrayElementTypeDesc.Type, ilg), choiceName + "i", elements, text, choice, arrayNamePlusA, true, arrayElementTypeDesc.IsNullable); + WriteElements(new SourceInfo(arrayNamePlusI, null, null, arrayElementTypeDesc.Type, ilg), $"{choiceName}i", elements, text, choice, arrayNamePlusA, true, arrayElementTypeDesc.IsNullable); } else { @@ -1627,7 +1627,7 @@ private void WriteElements(SourceInfo source, string? enumSource, ElementAccesso { string fullTypeName = element.Mapping!.TypeDesc!.CSharpName; object? enumValue; - string enumFullName = enumTypeName + ".@" + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping!, out enumValue); + string enumFullName = $"{enumTypeName}.@{FindChoiceEnumValue(element, (EnumMapping)choice.Mapping!, out enumValue)}"; if (wroteFirstIf) ilg.InitElseIf(); else { wroteFirstIf = true; ilg.InitIf(); } @@ -1705,7 +1705,7 @@ private void WriteElements(SourceInfo source, string? enumSource, ElementAccesso if (choice != null) { object? enumValue; - enumFullName = enumTypeName + ".@" + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping!, out enumValue); + enumFullName = $"{enumTypeName}.@{FindChoiceEnumValue(element, (EnumMapping)choice.Mapping!, out enumValue)}"; labelFalse = ilg.DefineLabel(); labelEnd = ilg.DefineLabel(); ILGenLoad(enumSource!, choice == null ? null : choice.Mapping!.TypeDesc!.Type); @@ -2312,7 +2312,7 @@ private string FindChoiceEnumValue(ElementAccessor element, EnumMapping choiceMa throw new InvalidOperationException(SR.Format(SR.XmlChoiceMissingAnyValue, choiceMapping.TypeDesc!.FullName)); } // Type {0} is missing value for '{1}'. - throw new InvalidOperationException(SR.Format(SR.XmlChoiceMissingValue, choiceMapping.TypeDesc!.FullName, element.Namespace + ":" + element.Name, element.Name, element.Namespace)); + throw new InvalidOperationException(SR.Format(SR.XmlChoiceMissingValue, choiceMapping.TypeDesc!.FullName, $"{element.Namespace}:{element.Name}", element.Name, element.Namespace)); } CodeIdentifier.CheckValidIdentifier(enumValue); return enumValue; @@ -2358,12 +2358,12 @@ internal void ILGenForEnumLongValue(CodeGenerator ilg, string variable) internal string GetStringForTypeof(string typeFullName) { { - return "typeof(" + typeFullName + ")"; + return $"typeof({typeFullName})"; } } internal string GetStringForMember(string obj, string memberName, TypeDesc typeDesc) { - return obj + ".@" + memberName; + return $"{obj}.@{memberName}"; } internal SourceInfo GetSourceForMember(string obj, MemberMapping member, TypeDesc typeDesc, CodeGenerator ilg) { @@ -2381,12 +2381,12 @@ internal void ILGenForEnumMember(CodeGenerator ilg, Type type, string memberName internal string GetStringForArrayMember(string? arrayName, string subscript, TypeDesc arrayTypeDesc) { { - return arrayName + "[" + subscript + "]"; + return $"{arrayName}[{subscript}]"; } } internal string GetStringForMethod(string obj, string typeFullName, string memberName) { - return obj + "." + memberName + "("; + return $"{obj}.{memberName}("; } [RequiresUnreferencedCode("calls ILGenForCreateInstance")] @@ -2587,7 +2587,7 @@ internal void WriteInstanceOf(SourceInfo source, Type type, CodeGenerator ilg) [RequiresUnreferencedCode("calls Load")] internal void WriteArrayLocalDecl(string typeName, string variableName, SourceInfo initValue, TypeDesc arrayTypeDesc) { - Debug.Assert(typeName == arrayTypeDesc.CSharpName || typeName == arrayTypeDesc.CSharpName + "[]"); + Debug.Assert(typeName == arrayTypeDesc.CSharpName || typeName == $"{arrayTypeDesc.CSharpName}[]"); Type localType = (typeName == arrayTypeDesc.CSharpName) ? arrayTypeDesc.Type! : arrayTypeDesc.Type!.MakeArrayType(); // This may need reused variable to get code compat? LocalBuilder local = initValue.ILG.DeclareOrGetLocal(localType, variableName); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/ValidateNames.cs b/src/libraries/System.Private.Xml/src/System/Xml/ValidateNames.cs index cce4cf01d5a683..602a972e5c5687 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/ValidateNames.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/ValidateNames.cs @@ -603,7 +603,7 @@ private static bool ValidateNameInternal(string prefix, string localName, string /// private static string CreateName(string prefix, string localName) { - return (prefix.Length != 0) ? prefix + ":" + localName : localName; + return (prefix.Length != 0) ? $"{prefix}:{localName}" : localName; } /// diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/ExtensionQuery.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/ExtensionQuery.cs index b829ef3c9345b4..ab28f99c7ddfd1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/ExtensionQuery.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/ExtensionQuery.cs @@ -122,7 +122,7 @@ public override int CurrentPosition return value.ToString()!; } - protected string QName { get { return prefix.Length != 0 ? prefix + ":" + name : name; } } + protected string QName { get { return prefix.Length != 0 ? $"{prefix}:{name}" : name; } } public override int Count { get { return _queryIterator == null ? 1 : _queryIterator.Count; } } public override XPathResultType StaticType { get { return XPathResultType.Any; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathException.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathException.cs index 3b1a9fe8df4a32..829541715d31dd 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathException.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathException.cs @@ -105,12 +105,12 @@ private static string CreateMessage(string res, string?[]? args) { string message = args == null ? res : string.Format(res, args); if (message == null) - message = "UNKNOWN(" + res + ")"; + message = $"UNKNOWN({res})"; return message; } catch (MissingManifestResourceException) { - return "UNKNOWN(" + res + ")"; + return $"UNKNOWN({res})"; } } 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 6568055ff2d6a6..965213102cf06d 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 @@ -1381,14 +1381,14 @@ public virtual string OuterXml // Attributes and namespaces are not allowed at the top-level by the well-formed writer if (NodeType == XPathNodeType.Attribute) { - return string.Concat(Name, "=\"", Value, "\""); + return $"{Name}=\"{Value}\""; } else if (NodeType == XPathNodeType.Namespace) { if (LocalName.Length == 0) - return string.Concat("xmlns=\"", Value, "\""); + return $"xmlns=\"{Value}\""; else - return string.Concat("xmlns:", LocalName, "=\"", Value, "\""); + return $"xmlns:{LocalName}=\"{Value}\""; } stringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -2228,19 +2228,19 @@ public override string ToString() switch (_nav.NodeType) { case XPathNodeType.Element: - result += ", Name=\"" + _nav.Name + '"'; + result += $", Name=\"{_nav.Name}\""; break; case XPathNodeType.Attribute: case XPathNodeType.Namespace: case XPathNodeType.ProcessingInstruction: - result += ", Name=\"" + _nav.Name + '"'; - result += ", Value=\"" + XmlConvert.EscapeValueForDebuggerDisplay(_nav.Value) + '"'; + result += $", Name=\"{_nav.Name}\""; + result += $", Value=\"{XmlConvert.EscapeValueForDebuggerDisplay(_nav.Value)}\""; break; case XPathNodeType.Text: case XPathNodeType.Whitespace: case XPathNodeType.SignificantWhitespace: case XPathNodeType.Comment: - result += ", Value=\"" + XmlConvert.EscapeValueForDebuggerDisplay(_nav.Value) + '"'; + result += $", Value=\"{XmlConvert.EscapeValueForDebuggerDisplay(_nav.Value)}\""; break; } return result; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathNavigatorReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathNavigatorReader.cs index 2b9a0eb0a81e97..8b0bbc78d81b45 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathNavigatorReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathNavigatorReader.cs @@ -1024,7 +1024,7 @@ public override bool Read() } else if (_depth > 0 && _nav.MoveToParent()) { - Debug.Assert(_nav.NodeType == XPathNodeType.Element, _nav.NodeType.ToString() + " == XPathNodeType.Element"); + Debug.Assert(_nav.NodeType == XPathNodeType.Element, $"{_nav.NodeType} == XPathNodeType.Element"); _nodeType = XmlNodeType.EndElement; _state = State.EndElement; _depth--; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XmlException.cs b/src/libraries/System.Private.Xml/src/System/Xml/XmlException.cs index 7d8276f0851b56..418dfb17d38f59 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XmlException.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XmlException.cs @@ -208,7 +208,7 @@ private static string CreateMessage(string res, string?[]? args, int lineNumber, } catch (MissingManifestResourceException) { - return "UNKNOWN(" + res + ")"; + return $"UNKNOWN({res})"; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs index e02699f4abe807..6df4baafd7bd90 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs @@ -143,7 +143,7 @@ public XmlILStorageMethods(Type storageType) if (storageType == typeof(byte[])) ToAtomicValue = typeof(XmlILStorageConverter).GetMethod("BytesToAtomicValue"); else if (storageType != typeof(XPathItem) && storageType != typeof(XPathNavigator)) - ToAtomicValue = typeof(XmlILStorageConverter).GetMethod(storageType.Name + "ToAtomicValue"); + ToAtomicValue = typeof(XmlILStorageConverter).GetMethod($"{storageType.Name}ToAtomicValue"); } } 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 9e142049756c61..c965fd75e69c96 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 @@ -93,7 +93,7 @@ public static StorageDescriptor Local(LocalBuilder loc, Type itemStorageType, bo { Debug.Assert(loc.LocalType == itemStorageType || typeof(IList<>).MakeGenericType(itemStorageType).IsAssignableFrom(loc.LocalType), - "Type " + itemStorageType + " does not match the local variable's type"); + $"Type {itemStorageType} does not match the local variable's type"); StorageDescriptor storage = default; storage._location = ItemLocation.Local; @@ -125,7 +125,7 @@ public static StorageDescriptor Global(MethodInfo methGlobal, Type itemStorageTy { Debug.Assert(methGlobal.ReturnType == itemStorageType || typeof(IList<>).MakeGenericType(itemStorageType).IsAssignableFrom(methGlobal.ReturnType), - "Type " + itemStorageType + " does not match the global method's return type"); + $"Type {itemStorageType} does not match the global method's return type"); StorageDescriptor storage = default; storage._location = ItemLocation.Global; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILConstructAnalyzer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILConstructAnalyzer.cs index 8e37d3eefc0781..71fad3e186cdae 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILConstructAnalyzer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILConstructAnalyzer.cs @@ -389,14 +389,14 @@ public override string ToString() { s += _constrMeth.ToString(); - s += ", " + _xstatesInitial; + s += $", {_xstatesInitial}"; if (_xstatesBeginLoop != PossibleXmlStates.None) { - s += " => " + _xstatesBeginLoop.ToString() + " => " + _xstatesEndLoop.ToString(); + s += $" => {_xstatesBeginLoop} => {_xstatesEndLoop}"; } - s += " => " + _xstatesFinal; + s += $" => {_xstatesFinal}"; if (!MightHaveAttributes) s += ", NoAttrs"; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs index 006865b50b4c07..3d092041765567 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs @@ -29,7 +29,7 @@ internal sealed class XmlILModule private Hashtable _methods; private readonly bool _useLRE, _emitSymbols; - private const string RuntimeName = "{" + XmlReservedNs.NsXslDebug + "}" + "runtime"; + private const string RuntimeName = $"{{{XmlReservedNs.NsXslDebug}}}runtime"; private static ModuleBuilder CreateLREModule() { @@ -127,7 +127,7 @@ public MethodInfo DefineMethod(string name, Type returnType, Type[] paramTypes, { // Add unique id to end of name in order to make it unique within this module uniqueId++; - name = nameOrig + " (" + uniqueId + ")"; + name = $"{nameOrig} ({uniqueId})"; } if (!isRaw) @@ -275,7 +275,7 @@ private static AssemblyName CreateAssemblyName() System.Threading.Interlocked.Increment(ref s_assemblyId); name = new AssemblyName(); - name.Name = "System.Xml.Xsl.CompiledQuery." + s_assemblyId; + name.Name = $"System.Xml.Xsl.CompiledQuery.{s_assemblyId}"; return name; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs index fb15bb3ecc6c48..6e893aadb868c8 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs @@ -332,7 +332,7 @@ protected override QilNode Visit(QilNode nd) /// protected override QilNode VisitChildren(QilNode parent) { - Debug.Fail("Visit" + parent.NodeType + " should never be called"); + Debug.Fail($"Visit{parent.NodeType} should never be called"); return parent; } @@ -1768,7 +1768,7 @@ private void Compare(QilBinary ndComp) break; default: - Debug.Fail("Comparisons for datatype " + code + " are invalid."); + Debug.Fail($"Comparisons for datatype {code} are invalid."); break; } } @@ -3676,7 +3676,7 @@ protected override QilNode VisitXsltInvokeEarlyBound(QilInvokeEarlyBound ndInvok NestedVisitEnsureStack(ndActualArg, typeof(XPathItem), false); } else - Debug.Fail("Internal Xslt library may not use parameters of type " + clrTypeFormalArg); + Debug.Fail($"Internal Xslt library may not use parameters of type {clrTypeFormalArg}"); } else { @@ -3806,7 +3806,7 @@ protected override QilNode VisitXsltConvert(QilTargetType ndConv) // If a conversion could not be found, then convert the source expression to item or item* and try again NestedVisitEnsureStack(ndConv.Source, typeof(XPathItem), !typSrc.IsSingleton); if (!GetXsltConvertMethod(typSrc.IsSingleton ? TypeFactory.Item : TypeFactory.ItemS, typDst, out meth)) - Debug.Fail("Conversion from " + ndConv.Source.XmlType + " to " + ndConv.TargetType + " is not supported."); + Debug.Fail($"Conversion from {ndConv.Source.XmlType} to {ndConv.TargetType} is not supported."); } // XsltConvert.XXXToYYY(value); @@ -4693,7 +4693,8 @@ private void EndNestedIterator(QilNode nd) _iterCurr.Storage.ItemStorageType == GetItemStorageType(nd) || _iterCurr.Storage.ItemStorageType == typeof(XPathItem) || nd.XmlType!.TypeCode == XmlTypeCode.None, - "QilNodeType " + nd.NodeType + " cannot be stored using type " + _iterCurr.Storage.ItemStorageType + "."); + $"QilNodeType {nd.NodeType} cannot be stored using type {_iterCurr.Storage.ItemStorageType}." + ); // If the nested iterator was constructed in branching mode, if (_iterCurr.IsBranching) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs index f7810e1a524c5d..d591f341235b9f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs @@ -74,7 +74,7 @@ public string QualifiedName } else { - return _prefix + ':' + _local; + return $"{_prefix}:{_local}"; } } } @@ -139,10 +139,10 @@ public override string ToString() if (_uri.Length == 0) return _local; - return string.Concat("{", _uri, "}", _local); + return $"{{{_uri}}}{_local}"; } - return string.Concat("{", _uri, "}", _prefix, ":", _local); + return $"{{{_uri}}}{_prefix}:{_local}"; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTypeChecker.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTypeChecker.cs index 592c9a3f1173bf..f23c823cd0914b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTypeChecker.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilTypeChecker.cs @@ -1004,51 +1004,51 @@ private void CheckLiteralValue(QilNode node, Type clrTypeValue) Check(node is QilLiteral, node, "Node must be instance of QilLiteral"); Type clrType = ((QilLiteral)node).Value!.GetType(); - Check(clrTypeValue.IsAssignableFrom(clrType), node, "Literal value must be of type " + clrTypeValue.Name); + Check(clrTypeValue.IsAssignableFrom(clrType), node, $"Literal value must be of type {clrTypeValue.Name}"); } [Conditional("DEBUG")] private void CheckClass(QilNode node, Type clrTypeClass) { - Check(clrTypeClass.IsAssignableFrom(node.GetType()), node, "Node must be instance of " + clrTypeClass.Name); + Check(clrTypeClass.IsAssignableFrom(node.GetType()), node, $"Node must be instance of {clrTypeClass.Name}"); } [Conditional("DEBUG")] private void CheckClassAndNodeType(QilNode node, Type clrTypeClass, QilNodeType nodeType) { CheckClass(node, clrTypeClass); - Check(node.NodeType == nodeType, node, "Node must have QilNodeType." + nodeType); + Check(node.NodeType == nodeType, node, $"Node must have QilNodeType.{nodeType}"); } [Conditional("DEBUG")] private void CheckXmlType(QilNode node, XmlQueryType xmlType) { - Check(node.XmlType!.IsSubtypeOf(xmlType), node, "Node's type " + node.XmlType + " is not a subtype of " + xmlType); + Check(node.XmlType!.IsSubtypeOf(xmlType), node, $"Node's type {node.XmlType} is not a subtype of {xmlType}"); } [Conditional("DEBUG")] private void CheckNumericX(QilNode node) { - Check(node.XmlType!.IsNumeric && node.XmlType.IsSingleton && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict singleton numeric type"); + Check(node.XmlType!.IsNumeric && node.XmlType.IsSingleton && node.XmlType.IsStrict, node, $"Node's type {node.XmlType} must be a strict singleton numeric type"); } [Conditional("DEBUG")] private void CheckNumericXS(QilNode node) { - Check(node.XmlType!.IsNumeric && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict numeric type"); + Check(node.XmlType!.IsNumeric && node.XmlType.IsStrict, node, $"Node's type {node.XmlType} must be a strict numeric type"); } [Conditional("DEBUG")] private void CheckAtomicX(QilNode node) { - Check(node.XmlType!.IsAtomicValue && node.XmlType.IsStrict, node, "Node's type " + node.XmlType + " must be a strict atomic value type"); + Check(node.XmlType!.IsAtomicValue && node.XmlType.IsStrict, node, $"Node's type {node.XmlType} must be a strict atomic value type"); } [Conditional("DEBUG")] private void CheckNotDisjoint(QilBinary node) { Check(node.Left.XmlType!.IsSubtypeOf(node.Right.XmlType!) || node.Right.XmlType!.IsSubtypeOf(node.Left.XmlType), node, - "Node must not have arguments with disjoint types " + node.Left.XmlType + " and " + node.Right.XmlType); + $"Node must not have arguments with disjoint types {node.Left.XmlType} and {node.Right.XmlType}"); } private XmlQueryType DistinctType(XmlQueryType type) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilValidationVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilValidationVisitor.cs index 3a4d4805b44eb8..b6db4182a56b0d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilValidationVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilValidationVisitor.cs @@ -181,11 +181,9 @@ internal static void SetError(QilNode n, string message) #if QIL_TRACE_NODE_CREATION message += " ["+ n.NodeId + " (" + n.NodeType.ToString("G") + ")]"; #endif - - string? s = n.Annotation as string; - if (s != null) + if (n.Annotation is string s) { - message = s + "\n" + message; + message = $"{s}{Environment.NewLine}{message}"; } n.Annotation = message; Debug.Fail(message); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilXmlWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilXmlWriter.cs index b81a2a61f4beb7..4316ebf70add74 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilXmlWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilXmlWriter.cs @@ -115,7 +115,7 @@ private void WriteAnnotations(object? ann) } if (s != null && s.Length != 0) - this.writer.WriteComment(name != null && name.Length != 0 ? name + ": " + s : s); + this.writer.WriteComment(name != null && name.Length != 0 ? $"{name}: {s}" : s); } /// diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryContext.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryContext.cs index c696d59abe044c..b1f064c03ed935 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryContext.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryContext.cs @@ -301,7 +301,7 @@ public IList InvokeXsltLateBoundFunction(string name, string namespac objActualArgs[i] = args[i]; break; default: - Debug.Fail("This XmlTypeCode should never be inferred from a Clr type: " + xmlTypeFormalArg.TypeCode); + Debug.Fail($"This XmlTypeCode should never be inferred from a Clr type: {xmlTypeFormalArg.TypeCode}"); break; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryOutput.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryOutput.cs index f33347623eeb4f..ff568796cb0de2 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryOutput.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryOutput.cs @@ -1020,7 +1020,7 @@ private void WriteString(string text, bool disableOutputEscaping) break; default: - Debug.Fail("Text cannot be output in the " + _xstate + " state."); + Debug.Fail($"Text cannot be output in the {_xstate} state."); break; } @@ -1339,7 +1339,7 @@ private XPathNodeType XmlStateToNodeType(XmlState xstate) case XmlState.WithinPI: return XPathNodeType.ProcessingInstruction; } - Debug.Fail(xstate.ToString() + " is not a valid XmlState."); + Debug.Fail($"{xstate} is not a valid XmlState."); return XPathNodeType.Element; } @@ -1428,7 +1428,7 @@ private string RemapPrefix(string prefix, string ns, bool isElemPrefix) } // Rule #3: Otherwise, generate a new prefix of the form 'xp_??', where ?? is a stringized counter - genPrefix = "xp_" + (_prefixIndex++).ToString(CultureInfo.InvariantCulture); + genPrefix = string.Create(CultureInfo.InvariantCulture, $"xp_{_prefixIndex++}"); ReturnPrefix: diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryRuntime.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryRuntime.cs index 4415fa1b457f9e..1f43ba4e21b87e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryRuntime.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryRuntime.cs @@ -786,7 +786,7 @@ public bool MatchesXmlType(XPathItem item, XmlTypeCode code) break; } - Debug.Fail("XmlTypeCode " + code + " was not fully handled."); + Debug.Fail($"XmlTypeCode {code} was not fully handled."); return false; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltConvert.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltConvert.cs index a3d392d571c454..789af693b7befd 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltConvert.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltConvert.cs @@ -347,7 +347,7 @@ internal static XmlAtomicValue ConvertToType(XmlAtomicValue value, XmlQueryType break; } - Debug.Fail("Conversion from " + value.XmlType.QualifiedName.Name + " to " + destinationType + " is not supported."); + Debug.Fail($"Conversion from {value.XmlType.QualifiedName.Name} to {destinationType} is not supported."); return value; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltFunctions.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltFunctions.cs index c227f2cf9d3501..038e99f93dd18a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltFunctions.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltFunctions.cs @@ -302,7 +302,7 @@ public static string EXslObjectType(IList value) } else { - Debug.Fail("Unexpected type: " + o.GetType().ToString()); + Debug.Fail($"Unexpected type: {o.GetType()}"); return "external"; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathBuilder.cs index 80a5b06014e8ae..afbe996d494ed7 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathBuilder.cs @@ -127,7 +127,7 @@ public virtual QilNode Operator(XPathOperator op, QilNode? left, QilNode? right) case XPathOperatorGroup.Negate: return NegateOperator(op, left!); case XPathOperatorGroup.Union: return UnionOperator(op, left, right!); default: - Debug.Fail(op + " is not a valid XPathOperator"); + Debug.Fail($"{op} is not a valid XPathOperator"); return null; } } @@ -600,7 +600,7 @@ public virtual QilNode Function(string prefix, string name, IList args) case FuncId.Ceiling: return _f.InvokeCeiling(args[0]); case FuncId.Round: return _f.InvokeRound(args[0]); default: - Debug.Fail(func.id + " is present in the function table, but absent from the switch"); + Debug.Fail($"{func.id} is present in the function table, but absent from the switch"); return null; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathQilFactory.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathQilFactory.cs index d27a7d3470e3e3..72466b36240c1a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathQilFactory.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathQilFactory.cs @@ -180,7 +180,7 @@ public QilNode ConvertToType(XmlTypeCode requiredType, QilNode n) case XmlTypeCode.Boolean: return ConvertToBoolean(n); case XmlTypeCode.Node: return EnsureNodeSet(n); case XmlTypeCode.Item: return n; - default: Debug.Fail("Unexpected XmlTypeCode: " + requiredType); return null; + default: Debug.Fail($"Unexpected XmlTypeCode: {requiredType}"); return null; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathScanner.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathScanner.cs index b78f74bdf67bba..119f76a1b1201a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathScanner.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XPath/XPathScanner.cs @@ -582,7 +582,7 @@ private string LexKindToString(LexKind t) case LexKind.String: return ""; case LexKind.Eof: return ""; default: - Debug.Fail("Unexpected LexKind: " + t.ToString()); + Debug.Fail($"Unexpected LexKind: {t}"); return string.Empty; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlIlGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlIlGenerator.cs index 19dbf13cf50a1a..66c01b7cde8224 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlIlGenerator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlIlGenerator.cs @@ -357,7 +357,7 @@ public void CreateTypeInitializer(XmlQueryStaticData staticData) ConstructorInfo cctor; staticData.GetObjectData(out data, out ebTypes); - fldInitData = _module!.DefineInitializedData("__" + XmlQueryStaticData.DataFieldName, data); + fldInitData = _module!.DefineInitializedData($"__{XmlQueryStaticData.DataFieldName}", data); fldData = _module.DefineField(XmlQueryStaticData.DataFieldName, typeof(object)); fldTypes = _module.DefineField(XmlQueryStaticData.TypesFieldName, typeof(Type[])); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQualifiedNameTest.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQualifiedNameTest.cs index a3af660f0379e6..11c7986fad96f6 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQualifiedNameTest.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQualifiedNameTest.cs @@ -128,15 +128,15 @@ public override string ToString() } else if ((object)this.Namespace == (object)wildcard) { - return "*:" + this.Name; + return $"*:{this.Name}"; } else if (_exclude) { - return "{~" + this.Namespace + "}:" + this.Name; + return $"{{~{this.Namespace}}}:{this.Name}"; } else { - return "{" + this.Namespace + "}:" + this.Name; + return $"{{{this.Namespace}}}:{this.Name}"; } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs index be4b0fbc9e8543..db6f5130c7ae54 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs @@ -573,7 +573,7 @@ private string ItemTypeToString(bool isXQ) if (!isXQ) goto case XmlTypeCode.Element; - s += "{(element" + NameAndType(true) + "?&text?&comment?&processing-instruction?)*}"; + s += $"{{(element{NameAndType(true)}?&text?&comment?&processing-instruction?)*}}"; break; case XmlTypeCode.Element: @@ -586,7 +586,7 @@ private string ItemTypeToString(bool isXQ) { // Get QualifiedName from SchemaType if (SchemaType.QualifiedName.IsEmpty) - s = "<:" + s_typeNames[(int)TypeCode]; + s = $"<:{s_typeNames[(int)TypeCode]}"; else s = QNameToString(SchemaType.QualifiedName); } @@ -613,7 +613,7 @@ private string NameAndType(bool isXQ) if (SchemaType.QualifiedName.IsEmpty) { - typeName = "typeof(" + nodeName + ")"; + typeName = $"typeof({nodeName})"; } else { @@ -628,7 +628,7 @@ private string NameAndType(bool isXQ) if (nodeName == "*" && typeName == "*") return ""; - return "(" + nodeName + ", " + typeName + ")"; + return $"({nodeName}, {typeName})"; } /// @@ -649,15 +649,15 @@ private static string QNameToString(XmlQualifiedName name) } else if (name.Namespace == XmlReservedNs.NsXs) { - return "xs:" + name.Name; + return $"xs:{name.Name}"; } else if (name.Namespace == XmlReservedNs.NsXQueryDataType) { - return "xdt:" + name.Name; + return $"xdt:{name.Name}"; } else { - return "{" + name.Namespace + "}" + name.Name; + return $"{{{name.Namespace}}}{name.Name}"; } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs index 0acdd26877eef9..d53342bc8dda04 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs @@ -1176,7 +1176,7 @@ public static void Serialize(BinaryWriter writer, XmlQueryType type) subtypeId = 2; else { - Debug.Fail("Don't know how to serialize " + type.GetType().ToString()); + Debug.Fail($"Don't know how to serialize {type.GetType()}"); subtypeId = -1; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XslException.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XslException.cs index da6068cb4bf7cd..242c92117a3385 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XslException.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XslException.cs @@ -56,7 +56,7 @@ internal static string CreateMessage(string res, params string?[]? args) StringBuilder sb = new StringBuilder(res); if (args != null && args.Length > 0) { - Debug.Fail("Resource string '" + res + "' was not found"); + Debug.Fail($"Resource string '{res}' was not found"); sb.Append('('); sb.Append(args[0]); for (int idx = 1; idx < args.Length; idx++) @@ -81,11 +81,11 @@ public override string ToString() string info = FormatDetailedMessage(); if (info != null && info.Length > 0) { - result += ": " + info; + result += $": {info}"; } if (InnerException != null) { - result += " ---> " + InnerException.ToString() + Environment.NewLine + " " + CreateMessage(SR.Xml_EndOfInnerExceptionStack); + result += $" ---> {InnerException}{Environment.NewLine} {CreateMessage(SR.Xml_EndOfInnerExceptionStack)}"; } if (StackTrace != null) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs index c8ad0097517fbd..7377607cbb0d5b 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs @@ -192,7 +192,7 @@ public static string ConstructQName(string prefix, string localName) } else { - return prefix + ':' + localName; + return $"{prefix}:{localName}"; } } @@ -252,7 +252,7 @@ public void ValidatePiName(string name, IErrorHelper errorHelper) public string CreatePhantomNamespace() { // Prepend invalid XmlChar to ensure this name would not clash with any namespace name in the stylesheet - return "\0namespace" + _phantomNsCounter++; + return $"\0namespace{_phantomNsCounter++}"; } public bool IsPhantomNamespace(string namespaceName) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs index 2352c31d00c061..1a9097fed7c7db 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs @@ -462,7 +462,7 @@ private QilIterator GetNsVar(QilList nsList) } } QilIterator newVar = _f.Let(nsList); - newVar.DebugName = _f.QName("ns" + _nsVars.Count, XmlReservedNs.NsXslDebug).ToString(); + newVar.DebugName = _f.QName($"ns{_nsVars.Count}", XmlReservedNs.NsXslDebug).ToString(); _gloVars.Add(newVar); _nsVars.Add(newVar); return newVar; @@ -568,7 +568,7 @@ private void PrecompileProtoTemplatesHeaders() ChooseBestType(xslPar) ); paramFunc.SourceLine = SourceLineInfo.NoSource; - paramFunc.DebugName = ""; + paramFunc.DebugName = $""; param.DefaultValue = _f.Invoke(paramFunc, paramActual); // store VarPar here to compile it on next pass: if (paramWithCalls == null) @@ -742,7 +742,7 @@ private QilNode CompileInstructions(IList instructions, int from, QilLi case XslNodeType.ValueOfDoe: result = CompileValueOfDoe(node); break; case XslNodeType.Variable: result = CompileVariable(node); break; // case XslNodeType.WithParam: wrapped by CallTemplate or ApplyTemplates, see CompileWithParam() - default: Debug.Fail("Unexpected type of AST node: " + nodeType.ToString()); result = null; break; + default: Debug.Fail($"Unexpected type of AST node: {nodeType}"); result = null; break; } ExitScope(); @@ -1186,7 +1186,7 @@ private QilNode CompileApplyTemplates(XslNodeEx node) if (IsDebug || !(val is QilIterator || val is QilLiteral)) { QilIterator let = _f.Let(val!); - let.DebugName = _f.QName("with-param " + withParam.Name!.QualifiedName, XmlReservedNs.NsXslDebug).ToString(); + let.DebugName = _f.QName($"with-param {withParam.Name!.QualifiedName}", XmlReservedNs.NsXslDebug).ToString(); _varHelper.AddVariable(let); withParam.Value = let; } @@ -1236,7 +1236,7 @@ private QilNode CompileCallTemplate(XslNodeEx node) { QilNode val = withParam.Value!; QilIterator let = _f.Let(val); - let.DebugName = _f.QName("with-param " + withParam.Name!.QualifiedName, XmlReservedNs.NsXslDebug).ToString(); + let.DebugName = _f.QName($"with-param {withParam.Name!.QualifiedName}", XmlReservedNs.NsXslDebug).ToString(); _varHelper.AddVariable(let); withParam.Value = let; } @@ -1872,7 +1872,7 @@ the same expanded-QName as the context node. case XmlNodeKindFlags.PI: return _f.And(_f.IsType(testNode, T.PI), _f.Eq(_f.LocalNameOf(testNode), _f.LocalNameOf(current))); case XmlNodeKindFlags.Namespace: return _f.And(_f.IsType(testNode, T.Namespace), _f.Eq(_f.LocalNameOf(testNode), _f.LocalNameOf(current))); default: - Debug.Fail("Unexpected NodeKind: " + nodeKinds.ToString()); + Debug.Fail($"Unexpected NodeKind: {nodeKinds}"); return _f.False(); } @@ -2685,8 +2685,8 @@ private QilNode InvokeApplyFunction(StylesheetLevel sheet, QilName mode, IList'; + string attMode = (mode.LocalName.Length == 0) ? string.Empty : $" mode=\"{mode.QualifiedName}\""; + applyFunction.DebugName = $"{(sheet is RootLevel ? ""; functionsForMode.Add(applyFunction); _functions.Add(applyFunction); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs index a9a2e410c1aa50..a873617549be40 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs @@ -132,7 +132,7 @@ QilNode IXPathEnvironment.ResolveFunction(string prefix, string name, IList args) } else { - Debug.Fail("Unexpected XmlQueryType for script function: " + xt.ToString()); + Debug.Fail($"Unexpected XmlQueryType for script function: {xt}"); } } } @@ -1453,7 +1453,7 @@ private void Refactor(XslNode parent, int split) var paramname = AstFactory.QName(variable.Name.LocalName, variable.Name.NamespaceUri, variable.Name.Prefix); // For each variable in scope, add xsl:with-param to the xsl:call-template - var withparam = AstFactory.VarPar(XslNodeType.WithParam, paramname, '$' + paramname.QualifiedName, XslVersion.Current); + var withparam = AstFactory.VarPar(XslNodeType.WithParam, paramname, $"${paramname.QualifiedName}", XslVersion.Current); XsltLoader.SetInfo(withparam, null, fakeCtxInfo); withparam.Namespaces = variable.Namespaces; calltemplate.AddContent(withparam); 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 f203642824f61d..defdca702a6b00 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 string QualifiedName { get { return prefix.Length == 0 ? localName : $"{prefix}:{localName}"; } } } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/BuilderInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/BuilderInfo.cs index 5931e93918ed0e..3f531acd48aab2 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/BuilderInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/BuilderInfo.cs @@ -99,7 +99,7 @@ internal string Name { if (localName.Length > 0) { - _name = prefix + ":" + localName; + _name = $"{prefix}:{localName}"; } else { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/Compiler.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/Compiler.cs index 3c86fe279171a4..51bf1db2ac3ddb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/Compiler.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/Compiler.cs @@ -746,13 +746,13 @@ internal int AddQuery(string xpathQuery, bool allowVar, bool allowKey, bool isPa internal int AddStringQuery(string xpathQuery) { - string modifiedQuery = XmlCharType.IsOnlyWhitespace(xpathQuery) ? xpathQuery : "string(" + xpathQuery + ")"; + string modifiedQuery = XmlCharType.IsOnlyWhitespace(xpathQuery) ? xpathQuery : $"string({xpathQuery})"; return AddQuery(modifiedQuery); } internal int AddBooleanQuery(string xpathQuery) { - string modifiedQuery = XmlCharType.IsOnlyWhitespace(xpathQuery) ? xpathQuery : "boolean(" + xpathQuery + ")"; + string modifiedQuery = XmlCharType.IsOnlyWhitespace(xpathQuery) ? xpathQuery : $"boolean({xpathQuery})"; return AddQuery(modifiedQuery); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/NavigatorOutput.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/NavigatorOutput.cs index c4471b42795735..075a2904bf7ddc 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/NavigatorOutput.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/NavigatorOutput.cs @@ -83,7 +83,7 @@ public Processor.OutputResult RecordDone(RecordBuilder record) break; default: - Debug.Fail("Invalid NodeType on output: " + mainNode.NodeType); + Debug.Fail($"Invalid NodeType on output: {mainNode.NodeType}"); break; } record.Reset(); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/ReaderOutput.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/ReaderOutput.cs index 0e27790aa6029c..4bfe6cdf71d298 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/ReaderOutput.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/ReaderOutput.cs @@ -71,7 +71,7 @@ public override string Name { if (localName.Length > 0) { - return _nameTable.Add(prefix + ":" + localName); + return _nameTable.Add($"{prefix}:{localName}"); } else { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/VariableAction.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/VariableAction.cs index 3703e24b949998..3c3cfddf1b61ae 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/VariableAction.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/VariableAction.cs @@ -78,7 +78,7 @@ internal override void Compile(Compiler compiler) } if (this.containedActions != null) { - baseUri = baseUri + '#' + compiler.GetUnicRtfId(); + baseUri = $"{baseUri}#{compiler.GetUnicRtfId()}"; } else { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/WriterOutput.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/WriterOutput.cs index ae66561a5e3cdc..3e9d0054ec71dc 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/WriterOutput.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/WriterOutput.cs @@ -75,7 +75,7 @@ public Processor.OutputResult RecordDone(RecordBuilder record) case XmlNodeType.EndEntity: break; default: - Debug.Fail("Invalid NodeType on output: " + mainNode.NodeType); + Debug.Fail($"Invalid NodeType on output: {mainNode.NodeType}"); break; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xslt/XsltException.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xslt/XsltException.cs index 3136e02340e08f..f15e00850bbb2d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xslt/XsltException.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xslt/XsltException.cs @@ -123,13 +123,13 @@ private static string CreateMessage(string res, string?[]? args, string? sourceU string message = FormatMessage(res, args); if (res != SR.Xslt_CompileError && lineNumber != 0) { - message += " " + FormatMessage(SR.Xml_ErrorFilePosition, sourceUri, lineNumber.ToString(CultureInfo.InvariantCulture), linePosition.ToString(CultureInfo.InvariantCulture)); + message += $" {FormatMessage(SR.Xml_ErrorFilePosition, sourceUri, lineNumber.ToString(CultureInfo.InvariantCulture), linePosition.ToString(CultureInfo.InvariantCulture))}"; } return message; } catch (MissingManifestResourceException) { - return "UNKNOWN(" + res + ")"; + return $"UNKNOWN({res})"; } }