Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c79392

Browse files
authored
Clean up string formatting in a variety of places (#50267)
Mostly just replacing string.Format calls with equivalent interpolated string uses. In some cases, I replaced lots of string creations with a StringBuilder or equivalent.
1 parentc5eeedb commit0c79392

File tree

78 files changed

+219
-460
lines changed

Some content is hidden

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

78 files changed

+219
-460
lines changed

‎src/coreclr/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
usingSystem.Runtime.CompilerServices;
5-
usingSystem.Runtime.InteropServices;
64
usingSystem.Collections.Generic;
75
usingSystem.Diagnostics;
86
usingSystem.Diagnostics.CodeAnalysis;
7+
usingSystem.Runtime.CompilerServices;
8+
usingSystem.Runtime.InteropServices;
9+
usingSystem.Text;
910

1011
namespaceSystem.Reflection
1112
{
@@ -439,15 +440,33 @@ private void Init(object pca)
439440
#region Object Override
440441
publicoverridestringToString()
441442
{
442-
stringctorArgs="";
443-
for(inti=0;i<ConstructorArguments.Count;i++)
444-
ctorArgs+=string.Format(i==0?"{0}":", {0}",ConstructorArguments[i]);
443+
varvsb=newValueStringBuilder(stackallocchar[256]);
444+
445+
vsb.Append('[');
446+
vsb.Append(Constructor.DeclaringType!.FullName);
447+
vsb.Append('(');
448+
449+
boolfirst=true;
450+
451+
intcount=ConstructorArguments.Count;
452+
for(inti=0;i<count;i++)
453+
{
454+
if(!first)vsb.Append(", ");
455+
vsb.Append(ConstructorArguments[i].ToString());
456+
first=false;
457+
}
458+
459+
count=NamedArguments.Count;
460+
for(inti=0;i<count;i++)
461+
{
462+
if(!first)vsb.Append(", ");
463+
vsb.Append(NamedArguments[i].ToString());
464+
first=false;
465+
}
445466

446-
stringnamedArgs="";
447-
for(inti=0;i<NamedArguments.Count;i++)
448-
namedArgs+=string.Format(i==0&&ctorArgs.Length==0?"{0}":", {0}",NamedArguments[i]);
467+
vsb.Append(")]");
449468

450-
returnstring.Format("[{0}({1}{2})]",Constructor.DeclaringType!.FullName,ctorArgs,namedArgs);
469+
returnvsb.ToString();
451470
}
452471
publicoverrideintGetHashCode()=>base.GetHashCode();
453472
publicoverrideboolEquals(object?obj)=>obj==(object)this;

‎src/coreclr/System.Private.CoreLib/src/System/Reflection/MdImport.cs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,6 @@ internal sealed class MetadataException : Exception
557557
privateintm_hr;
558558
internalMetadataException(inthr){m_hr=hr;}
559559

560-
publicoverridestringToString()
561-
{
562-
returnstring.Format("MetadataException HResult = {0:x}.",m_hr);
563-
}
560+
publicoverridestringToString()=>$"MetadataException HResult ={m_hr:x}.";
564561
}
565562
}

‎src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal static unsafe string GetMessage(int errorCode, IntPtr moduleHandle)
7171
}
7272

7373
// Couldn't get a message, so manufacture one.
74-
returnstring.Format("Unknown error (0x{0:x})",errorCode);
74+
return$"Unknown error (0x{errorCode:x})";
7575
}
7676

7777
privatestaticstringGetAndTrimString(Span<char>buffer)

‎src/libraries/Common/src/System/Net/WebSockets/WebSocketValidate.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal static void ValidateSubprotocol(string subProtocol)
5858
charch=subProtocol[i];
5959
if(ch<0x21||ch>0x7e)
6060
{
61-
invalidChar=string.Format(CultureInfo.InvariantCulture,"[{0}]",(int)ch);
61+
invalidChar=$"[{(int)ch}]";
6262
break;
6363
}
6464

‎src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComTypeEnumDesc.cs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ internal sealed class ComTypeEnumDesc : ComTypeDesc, IDynamicMetaObjectProvider
1515
privatereadonlystring[]_memberNames;
1616
privatereadonlyobject[]_memberValues;
1717

18-
publicoverridestringToString()
19-
{
20-
returnstring.Format(CultureInfo.CurrentCulture,"<enum '{0}'>",TypeName);
21-
}
18+
publicoverridestringToString()=>$"<enum '{TypeName}'>";
2219

2320
internalComTypeEnumDesc(ComTypes.ITypeInfotypeInfo,ComTypeLibDesctypeLibDesc):
2421
base(typeInfo,typeLibDesc)

‎src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComTypeLibDesc.cs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ private ComTypeLibDesc()
3232
_classes=newLinkedList<ComTypeClassDesc>();
3333
}
3434

35-
publicoverridestringToString()
36-
{
37-
returnstring.Format(CultureInfo.CurrentCulture,"<type library {0}>",Name);
38-
}
35+
publicoverridestringToString()=>$"<type library{Name}>";
3936

4037
publicstringDocumentation
4138
{

‎src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallable.cs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ internal DispCallable(IDispatchComObject dispatch, string memberName, int dispId
1919
DispId=dispId;
2020
}
2121

22-
publicoverridestringToString()
23-
{
24-
returnstring.Format(CultureInfo.CurrentCulture,"<bound dispmethod {0}>",MemberName);
25-
}
22+
publicoverridestringToString()=>$"<bound dispmethod{MemberName}>";
2623

2724
publicIDispatchComObjectDispatchComObject{get;}
2825

‎src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchComObject.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public override string ToString()
9999
typeName="IDispatch";
100100
}
101101

102-
returnstring.Format(CultureInfo.CurrentCulture,"{0} ({1})",RuntimeCallableWrapper.ToString(),typeName);
102+
return$"{RuntimeCallableWrapper.ToString()} ({typeName})";
103103
}
104104

105105
publicComTypeDescComTypeDesc

‎src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/Variant.Extended.cs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ internal static System.Reflection.MethodInfo GetByrefSetter(VarEnum varType)
281281
}
282282
}
283283

284-
publicoverridestringToString()
285-
{
286-
returnstring.Format(CultureInfo.CurrentCulture,"Variant ({0})",VariantType);
287-
}
284+
publicoverridestringToString()=>$"Variant ({VariantType})";
288285

289286
publicvoidSetAsIConvertible(IConvertiblevalue)
290287
{

‎src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override void Load()
6060
{
6161
// "/SomeSwitch" is equivalent to "--SomeSwitch" when interpreting switch mappings
6262
// So we do a conversion to simplify later processing
63-
currentArg=string.Format("--{0}",currentArg.Substring(1));
63+
currentArg=$"--{currentArg.Substring(1)}";
6464
keyStartIndex=2;
6565
}
6666

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp