Skip to content

Commit 2661f63

Browse files
authored
Prefer use of Interpolated strings in project Presentation (#8519)
* use interpolated strings in PresentationFramework * review usage of string.Format in PresentationFramework
1 parent 20956ef commit 2661f63

File tree

146 files changed

+2069
-2136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+2069
-2136
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/MarkupCompiler.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,11 +1344,11 @@ private void InitializeTypeMapper()
13441344
}
13451345
if (XamlTypeMapper.AssemblyPC == null)
13461346
{
1347-
asmMissing += (asmMissing.Length > 0 ? ", " : string.Empty) + "PresentationCore";
1347+
asmMissing += $"{(asmMissing.Length > 0 ? ", " : string.Empty)}PresentationCore";
13481348
}
13491349
if (XamlTypeMapper.AssemblyPF == null)
13501350
{
1351-
asmMissing += (asmMissing.Length > 0 ? ", " : string.Empty) + "PresentationFramework";
1351+
asmMissing += $"{(asmMissing.Length > 0 ? ", " : string.Empty)}PresentationFramework";
13521352
}
13531353

13541354
if (asmMissing.Length > 0)
@@ -2410,7 +2410,7 @@ private static CodeTypeReference GenerateConstructedTypeReference(Type t, string
24102410
eventName,
24112411
ctrConstructedType.BaseType,
24122412
typeParam.FullName,
2413-
refTypeFullName + "<" + string.Join(",", typeArgsList) + ">");
2413+
$"{refTypeFullName}<{string.Join(",", typeArgsList)}>");
24142414
}
24152415
}
24162416
else
@@ -3565,9 +3565,9 @@ internal string SubClass
35653565
private const string SPLASHCLASSNAME = "SplashScreen";
35663566
private const string ARGS = "args";
35673567
private const string INITIALIZE_COMPONENT = "InitializeComponent";
3568-
private const string SWITCH_STATEMENT = INDENT12 + "switch (" + CONNECTIONID + ")\r\n" + INDENT12 + "{";
3569-
private const string BREAK_STATEMENT = INDENT12 + "break;";
3570-
private const string CASE_STATEMENT = INDENT12 + "case ";
3568+
private const string SWITCH_STATEMENT = $"{INDENT12}switch ({CONNECTIONID})\r\n{INDENT12}{{";
3569+
private const string BREAK_STATEMENT = $"{INDENT12}break;";
3570+
private const string CASE_STATEMENT = $"{INDENT12}case ";
35713571
private const string ENDCURLY = "}";
35723572
private const string COLON = ":";
35733573
private const string RESOURCE_LOCATER = "resourceLocater";

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/ParserExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public override bool GetElementType(
520520
else if (!_compiler.IsBamlNeeded && !_compiler.ProcessingRootContext && _compiler.IsCompilingEntryPointClass && xmlReader.Depth > 0)
521521
{
522522
if ((!localName.Equals(MarkupCompiler.CODETAG) &&
523-
!localName.Equals(MarkupCompiler.CODETAG + "Extension")) ||
523+
!localName.Equals($"{MarkupCompiler.CODETAG}Extension")) ||
524524
!namespaceUri.Equals(XamlReaderHelper.DefinitionNamespaceURI))
525525
{
526526
_compiler.IsBamlNeeded = true;
@@ -666,7 +666,7 @@ public override void WriteEndAttributes(XamlEndAttributesNode xamlEndAttributesN
666666
if (MemberAttributes.Private != _fieldModifier &&
667667
MemberAttributes.Assembly != _fieldModifier)
668668
{
669-
MarkupCompiler.GenerateXmlComments(_nameField, _nameField.Name + " Name Field");
669+
MarkupCompiler.GenerateXmlComments(_nameField, $"{_nameField.Name} Name Field");
670670
}
671671

672672
_nameField.Attributes = _fieldModifier;

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs

Lines changed: 76 additions & 76 deletions
Large diffs are not rendered by default.

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/MergeLocalizationDirectives.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public override bool Execute()
7373

7474
Log.LogMessageFromResources(nameof(SR.CommentFileGenerating), _outputFile);
7575

76-
streamWriter.WriteLine("<" + LocComments.LocDocumentRoot + ">");
76+
streamWriter.WriteLine($"<{LocComments.LocDocumentRoot}>");
7777

7878
// keep things simple and fast. Just keep appending the
7979
// xml fragments that are already outputed.
@@ -86,7 +86,7 @@ public override bool Execute()
8686
}
8787
}
8888

89-
streamWriter.WriteLine("</" + LocComments.LocDocumentRoot + ">");
89+
streamWriter.WriteLine($"</{LocComments.LocDocumentRoot}>");
9090
Log.LogMessageFromResources(nameof(SR.CommentFileGenerated), _outputFile);
9191
}
9292
}

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,10 +1118,7 @@ private void WriteNewUid(Uid uid)
11181118
{
11191119
// construct the attribute name, e.g. x:Uid
11201120
// "x" will be the resolved namespace prefix for the definition namespace
1121-
string attributeName =
1122-
(uid.NamespacePrefix == null) ?
1123-
_collector.NamespaceAddedForMissingUid + ":" + XamlReaderHelper.DefinitionUid
1124-
: uid.NamespacePrefix + ":" + XamlReaderHelper.DefinitionUid;
1121+
string attributeName = $"{uid.NamespacePrefix ?? _collector.NamespaceAddedForMissingUid}:{XamlReaderHelper.DefinitionUid}";
11251122

11261123
// escape all the Xml entities in the value
11271124
string attributeValue = EscapedXmlEntities.Replace(

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/DataIdProcessor.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public DataIdProcessor(LocatorManager manager) : base(manager)
6565
#region Public Methods
6666

6767
/// <summary>
68-
/// If and only if the current node has a DataId set and has FetchAnnotationsAsBatch
68+
/// If and only if the current node has a DataId set and has FetchAnnotationsAsBatch
6969
/// set to true, then all annotations for the subtree rooted at this node are loaded
70-
/// at once.
70+
/// at once.
7171
/// </summary>
7272
/// <param name="node">node to process</param>
7373
/// <param name="calledProcessAnnotations">indicates the callback was called by
@@ -112,7 +112,7 @@ public override IList<IAttachedAnnotation> PreProcessNode(DependencyObject node,
112112
/// was returned as true by any node underneath this node</param>
113113
/// <param name="calledProcessAnnotations">indicates whether ProcessAnnotations was called
114114
/// by this method</param>
115-
/// <returns>
115+
/// <returns>
116116
/// a list of AttachedAnnotations loaded during the processing of
117117
/// the node; can be null if no annotations were loaded
118118
/// </returns>
@@ -155,7 +155,7 @@ public override IList<IAttachedAnnotation> PostProcessNode(DependencyObject node
155155
/// containing the id value is returned. Otherwise null is returned.
156156
/// </summary>
157157
/// <param name="node">the node to generate a locator for</param>
158-
/// <param name="continueGenerating">specifies whether or not generating should
158+
/// <param name="continueGenerating">specifies whether or not generating should
159159
/// continue for the rest of the path; always set to true</param>
160160
/// <returns>if node has a value for DataIdProperty, a locator with a
161161
/// single locator part containing the id value; null otherwise
@@ -179,27 +179,27 @@ public override ContentLocator GenerateLocator(PathNode node, out bool continueG
179179
}
180180

181181
/// <summary>
182-
/// Searches the logical tree for a node matching the values of
183-
/// locatorPart. The search begins with startNode.
182+
/// Searches the logical tree for a node matching the values of
183+
/// locatorPart. The search begins with startNode.
184184
/// </summary>
185-
/// <param name="locatorPart">locator part to be matched, must be of the type
185+
/// <param name="locatorPart">locator part to be matched, must be of the type
186186
/// handled by this processor</param>
187187
/// <param name="startNode">logical tree node to start search at</param>
188-
/// <param name="continueResolving">return flag indicating whether the search
188+
/// <param name="continueResolving">return flag indicating whether the search
189189
/// should continue (presumably because the search was not exhaustive)</param>
190-
/// <returns>returns a node that matches the locator part; null if no such
190+
/// <returns>returns a node that matches the locator part; null if no such
191191
/// node is found</returns>
192-
/// <exception cref="ArgumentNullException">locatorPart or startNode are
192+
/// <exception cref="ArgumentNullException">locatorPart or startNode are
193193
/// null</exception>
194-
/// <exception cref="ArgumentException">locatorPart is of the incorrect
194+
/// <exception cref="ArgumentException">locatorPart is of the incorrect
195195
/// type</exception>
196196
public override DependencyObject ResolveLocatorPart(ContentLocatorPart locatorPart, DependencyObject startNode, out bool continueResolving)
197197
{
198198
ArgumentNullException.ThrowIfNull(locatorPart);
199199
ArgumentNullException.ThrowIfNull(startNode);
200200

201201
if (DataIdElementName != locatorPart.PartType)
202-
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, locatorPart.PartType.Namespace + ":" + locatorPart.PartType.Name), "locatorPart");
202+
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, $"{locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}"), "locatorPart");
203203

204204
// Initial value
205205
continueResolving = true;
@@ -208,7 +208,7 @@ public override DependencyObject ResolveLocatorPart(ContentLocatorPart locatorPa
208208
string id = locatorPart.NameValuePairs[ValueAttributeName];
209209
if (id == null)
210210
{
211-
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, locatorPart.PartType.Namespace + ":" + locatorPart.PartType.Name), "locatorPart");
211+
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, $"{locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}"), "locatorPart");
212212
}
213213

214214
// and from the node to examine.
@@ -246,13 +246,13 @@ public override XmlQualifiedName[] GetLocatorPartTypes()
246246
//
247247
// Public Operators
248248
//
249-
//------------------------------------------------------
249+
//------------------------------------------------------
250250

251251
//------------------------------------------------------
252252
//
253253
// Public Events
254254
//
255-
//------------------------------------------------------
255+
//------------------------------------------------------
256256

257257
//------------------------------------------------------
258258
//
@@ -270,7 +270,7 @@ public override XmlQualifiedName[] GetLocatorPartTypes()
270270
public const String Id = "Id";
271271

272272
/// <summary>
273-
/// Used to specify a unique id for the data represented by a
273+
/// Used to specify a unique id for the data represented by a
274274
/// logical tree node. Attach this property to the element with a
275275
/// unique value.
276276
/// </summary>
@@ -421,7 +421,7 @@ private ContentLocatorPart CreateLocatorPart(DependencyObject node)
421421
/// <summary>
422422
/// Get the value of the DataId dependency property for a
423423
/// DependencyObject.
424-
/// </summary>
424+
/// </summary>
425425
/// <param name="d">the object whose DataId value is to be retrieved</param>
426426
/// <returns>the object's DataId, if it is set, null otherwise</returns>
427427
internal String GetNodeId(DependencyObject d)
@@ -450,7 +450,7 @@ internal String GetNodeId(DependencyObject d)
450450
#region Private Fields
451451

452452
/// <summary>
453-
/// The type name of locator parts handled by this handler.
453+
/// The type name of locator parts handled by this handler.
454454
/// This is internal and available to the processor that
455455
/// is closely aligned with this handler.
456456
/// </summary>

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/FixedPageProcessor.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// This processor looks for FixedPage elements. When generating
99
// locators it produces a locator part identifying the FixedPage's
1010
// index in the parent FixedDocument. When resolving, it looks for
11-
// the FixedPage in the required index. When processing it
11+
// the FixedPage in the required index. When processing it
1212
// processes annotations for any FixedPage it finds.
1313
//
1414
//
@@ -33,7 +33,7 @@ namespace MS.Internal.Annotations.Anchoring
3333
/// This processor looks for FixedPage elements. When generating
3434
/// locators it produces a locator part identifying the FixedPage's
3535
/// index in the parent FixedDocument. When resolving, it looks for
36-
/// the FixedPage in the required index. When processing it
36+
/// the FixedPage in the required index. When processing it
3737
/// processes annotations for any FixedPage it finds.
3838
/// </summary>
3939
internal class FixedPageProcessor : SubTreeProcessor
@@ -66,7 +66,7 @@ public FixedPageProcessor(LocatorManager manager) : base(manager)
6666
#region Public Methods
6767

6868
/// <summary>
69-
/// If the node is a 'chunk' of fingerprintable text,
69+
/// If the node is a 'chunk' of fingerprintable text,
7070
/// LocatorManager.ProcessAnnotations is called.
7171
/// </summary>
7272
/// <param name="node">node to process</param>
@@ -95,17 +95,17 @@ public override IList<IAttachedAnnotation> PreProcessNode(DependencyObject node,
9595
}
9696

9797
/// <summary>
98-
/// Generates locators identifying 'chunks'. If node is a chunk,
99-
/// generates a locator with a single locator part containing a
98+
/// Generates locators identifying 'chunks'. If node is a chunk,
99+
/// generates a locator with a single locator part containing a
100100
/// fingerprint of the chunk. Otherwise null is returned.
101101
/// </summary>
102102
/// <param name="node">the node to generate a locator for</param>
103-
/// <param name="continueGenerating">return flag indicating whether the search
104-
/// should continue (presumably because the search was not exhaustive).
105-
/// This processor will always return true because it is possible to locate
103+
/// <param name="continueGenerating">return flag indicating whether the search
104+
/// should continue (presumably because the search was not exhaustive).
105+
/// This processor will always return true because it is possible to locate
106106
/// parts of the node (if it is FixedPage or FixedPageProxy)</param>
107-
/// <returns>if node is a FixedPage or FixedPageProxy, a ContentLocator
108-
/// with a single locator part containing the page number; null if node is not
107+
/// <returns>if node is a FixedPage or FixedPageProxy, a ContentLocator
108+
/// with a single locator part containing the page number; null if node is not
109109
/// FixedPage or FixedPageProxy </returns>
110110
/// <exception cref="ArgumentNullException">node is null</exception>
111111
/// <exception cref="ArgumentException">node points to a Document Page View which
@@ -150,32 +150,32 @@ public override ContentLocator GenerateLocator(PathNode node, out bool continueG
150150
}
151151

152152
/// <summary>
153-
/// Searches the logical tree for a node matching the values of
153+
/// Searches the logical tree for a node matching the values of
154154
/// locatorPart. A match must be a chunk which produces the same
155-
/// fingerprint as in the locator part.
155+
/// fingerprint as in the locator part.
156156
/// </summary>
157-
/// <param name="locatorPart">locator part to be matched, must be of the type
157+
/// <param name="locatorPart">locator part to be matched, must be of the type
158158
/// handled by this processor</param>
159159
/// <param name="startNode">logical tree node to start search at</param>
160-
/// <param name="continueResolving">return flag indicating whether the search
160+
/// <param name="continueResolving">return flag indicating whether the search
161161
/// should continue (presumably because the search was not exhaustive). This
162162
/// processor will return false if the startNode is a FixedPage
163163
/// with a different page number than the locator part's page number.
164164
/// Otherwise the return value will be true.
165165
/// inside the FixedPage(like TextSelection) </param>
166-
/// <returns>returns a node that matches the locator part; null if no such
166+
/// <returns>returns a node that matches the locator part; null if no such
167167
/// node is found</returns>
168-
/// <exception cref="ArgumentNullException">locatorPart or startNode are
168+
/// <exception cref="ArgumentNullException">locatorPart or startNode are
169169
/// null</exception>
170-
/// <exception cref="ArgumentException">locatorPart is of the incorrect
170+
/// <exception cref="ArgumentException">locatorPart is of the incorrect
171171
/// type</exception>
172172
public override DependencyObject ResolveLocatorPart(ContentLocatorPart locatorPart, DependencyObject startNode, out bool continueResolving)
173173
{
174174
ArgumentNullException.ThrowIfNull(locatorPart);
175175
ArgumentNullException.ThrowIfNull(startNode);
176176

177177
if (PageNumberElementName != locatorPart.PartType)
178-
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, locatorPart.PartType.Namespace + ":" + locatorPart.PartType.Name), "locatorPart");
178+
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, $"{locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}"), "locatorPart");
179179

180180
// Initial value
181181
continueResolving = true;
@@ -186,7 +186,7 @@ public override DependencyObject ResolveLocatorPart(ContentLocatorPart locatorPa
186186
if (pageNumberString != null)
187187
pageNumber = Int32.Parse(pageNumberString, NumberFormatInfo.InvariantInfo);
188188
else
189-
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, locatorPart.PartType.Namespace + ":" + locatorPart.PartType.Name), "locatorPart");
189+
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, $"{locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}"), "locatorPart");
190190

191191

192192
// Get the actual FixedPage for the page number specified in the LocatorPart. We need
@@ -274,7 +274,7 @@ public override XmlQualifiedName[] GetLocatorPartTypes()
274274
//
275275
//------------------------------------------------------
276276

277-
#region Public Properties
277+
#region Public Properties
278278

279279
/// <summary>
280280
/// Id used to register this processor with the LocatorManager. Registration
@@ -313,7 +313,7 @@ internal bool UseLogicalTree
313313

314314
/// <summary>
315315
/// Creates an instance of the locator part type handled by this
316-
/// handler that represents node.
316+
/// handler that represents node.
317317
/// </summary>
318318
/// <param name="page">FixedPage for which a locator part will be created</param>
319319
/// <returns>

0 commit comments

Comments
 (0)