Skip to content

Commit 998a0e3

Browse files
committed
Using interpolated strings for better code readability.
1 parent ab614d9 commit 998a0e3

24 files changed

+65
-81
lines changed

projects/Apigen/apigen/AmqpEntity.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,10 @@ public string DocumentationComment(string prefixSpaces, string docXpath) {
8282
public string DocumentationComment(string prefixSpaces, string docXpath, string tagname) {
8383
string docStr = GetString(docXpath, "").Trim();
8484
if (docStr.Length > 0) {
85-
return (prefixSpaces + "/// <"+tagname+">\n" +
86-
GetString(docXpath, "") + "\n</"+tagname+">")
87-
.Replace("\n", "\n" + prefixSpaces + "/// ");
85+
return $"{prefixSpaces}/// <{tagname}>\n{GetString(docXpath, "")}\n</{tagname}>"
86+
.Replace("\n", $"\n{prefixSpaces}/// ");
8887
} else {
89-
return prefixSpaces + "// (no documentation)";
88+
return $"{prefixSpaces}// (no documentation)";
9089
}
9190
}
9291
}

projects/Apigen/apigen/Apigen.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static string GetString(XmlNode n0, string path)
9999
string s = GetString(n0, path, null);
100100
if (s == null)
101101
{
102-
throw new Exception("Missing spec XML node: " + path);
102+
throw new Exception($"Missing spec XML node: {path}");
103103
}
104104
return s;
105105
}
@@ -248,7 +248,7 @@ public void HandleOption(string opt)
248248
}
249249
else
250250
{
251-
Console.Error.WriteLine("Unsupported command-line option: " + opt);
251+
Console.Error.WriteLine($"Unsupported command-line option: {opt}");
252252
Usage();
253253
}
254254
}
@@ -294,7 +294,7 @@ public void Generate()
294294

295295
public void LoadSpec()
296296
{
297-
Console.WriteLine("* Loading spec from '" + m_inputXmlFilename + "'");
297+
Console.WriteLine($"* Loading spec from '{m_inputXmlFilename}'");
298298
m_spec = new XmlDocument();
299299

300300
using (var stream = new FileStream(m_inputXmlFilename, FileMode.Open, FileAccess.Read))
@@ -358,12 +358,12 @@ public string MapDomain(string d)
358358

359359
public string VersionToken()
360360
{
361-
return "v" + m_majorVersion + "_" + m_minorVersion;
361+
return $"v{m_majorVersion}_{m_minorVersion}";
362362
}
363363

364364
public void GenerateOutput()
365365
{
366-
Console.WriteLine("* Generating code into '" + m_outputFilename + "'");
366+
Console.WriteLine($"* Generating code into '{m_outputFilename}'");
367367

368368
string directory = Path.GetDirectoryName(m_outputFilename);
369369

@@ -1069,11 +1069,11 @@ public void EmitContentHeaderFactory(MethodInfo method)
10691069
EmitLine(" {");
10701070
if (Attribute(method, typeof(AmqpUnsupportedAttribute)) != null)
10711071
{
1072-
EmitLine(string.Format(" throw new UnsupportedMethodException(\"" + method.Name + "\");"));
1072+
EmitLine($" throw new UnsupportedMethodException(\"{method.Name}\");");
10731073
}
10741074
else
10751075
{
1076-
EmitLine(" return new " + MangleClass(contentClass) + "Properties();");
1076+
EmitLine($" return new {MangleClass(contentClass)}Properties();");
10771077
}
10781078
EmitLine(" }");
10791079
}
@@ -1101,7 +1101,7 @@ public void MaybeEmitModelMethod(MethodInfo method)
11011101
{
11021102
EmitModelMethodPreamble(method);
11031103
EmitLine(" {");
1104-
EmitLine(" throw new UnsupportedMethodException(\"" + method.Name + "\");");
1104+
EmitLine($" throw new UnsupportedMethodException(\"{method.Name}\");");
11051105
EmitLine(" }");
11061106
}
11071107
else
@@ -1198,7 +1198,7 @@ public void LookupAmqpMethod(MethodInfo method,
11981198

11991199
if (amqpClass == null || amqpMethod == null)
12001200
{
1201-
throw new Exception("Could not find AMQP class or method for IModel method " + method.Name);
1201+
throw new Exception($"Could not find AMQP class or method for IModel method {method.Name}");
12021202
}
12031203
}
12041204

@@ -1227,7 +1227,7 @@ public void EmitModelMethod(MethodInfo method)
12271227
: replyMapping.m_methodName);
12281228
if (amqpReplyMethod == null)
12291229
{
1230-
throw new Exception("Could not find AMQP reply method for IModel method " + method.Name);
1230+
throw new Exception($"Could not find AMQP reply method for IModel method {method.Name}");
12311231
}
12321232
}
12331233

@@ -1269,7 +1269,7 @@ public void EmitModelMethod(MethodInfo method)
12691269
string contentHeaderExpr =
12701270
contentHeaderParameter == null
12711271
? "null"
1272-
: " (" + MangleClass(amqpClass.Name) + "Properties) " + contentHeaderParameter.Name;
1272+
: $" ({MangleClass(amqpClass.Name)}Properties) {contentHeaderParameter.Name}";
12731273
string contentBodyExpr =
12741274
contentBodyParameter == null ? "null" : contentBodyParameter.Name;
12751275

@@ -1316,15 +1316,15 @@ public void EmitModelMethod(MethodInfo method)
13161316

13171317
if (nowaitParameter != null)
13181318
{
1319-
EmitLine(" if (" + nowaitParameter.Name + ") {");
1320-
EmitLine(" ModelSend(__req," + contentHeaderExpr + "," + contentBodyExpr + ");");
1319+
EmitLine($" if ({nowaitParameter.Name}) {{");
1320+
EmitLine($" ModelSend(__req,{contentHeaderExpr},{contentBodyExpr});");
13211321
if (method.ReturnType == typeof(void))
13221322
{
13231323
EmitLine(" return;");
13241324
}
13251325
else
13261326
{
1327-
EmitLine(" return " + nowaitExpression + ";");
1327+
EmitLine($" return {nowaitExpression};");
13281328
}
13291329
EmitLine(" }");
13301330
}
@@ -1334,7 +1334,7 @@ public void EmitModelMethod(MethodInfo method)
13341334

13351335
if (amqpReplyMethod == null)
13361336
{
1337-
EmitLine(" ModelSend(__req," + contentHeaderExpr + "," + contentBodyExpr + ");");
1337+
EmitLine($" ModelSend(__req,{contentHeaderExpr},{contentBodyExpr});");
13381338
}
13391339
else
13401340
{
@@ -1358,24 +1358,24 @@ public void EmitModelMethod(MethodInfo method)
13581358
string fieldPrefix = IsAmqpClass(method.ReturnType) ? "_" : "";
13591359

13601360
// No field mapping --> it's assumed to be a struct to fill in.
1361-
EmitLine(" " + method.ReturnType + " __result = new " + method.ReturnType + "();");
1361+
EmitLine($" {method.ReturnType} __result = new {method.ReturnType}();");
13621362
foreach (FieldInfo fi in method.ReturnType.GetFields())
13631363
{
13641364
if (Attribute(fi, typeof(AmqpFieldMappingAttribute)) is AmqpFieldMappingAttribute returnFieldMapping)
13651365
{
1366-
EmitLine(" __result." + fi.Name + " = __rep." + fieldPrefix + returnFieldMapping.m_fieldName + ";");
1366+
EmitLine($" __result.{fi.Name} = __rep.{fieldPrefix}{returnFieldMapping.m_fieldName};");
13671367
}
13681368
else
13691369
{
1370-
EmitLine(" __result." + fi.Name + " = __rep." + fieldPrefix + fi.Name + ";");
1370+
EmitLine($" __result.{fi.Name} = __rep.{fieldPrefix}{fi.Name};");
13711371
}
13721372
}
13731373
EmitLine(" return __result;");
13741374
}
13751375
else
13761376
{
13771377
// Field mapping --> return just the field we're interested in.
1378-
EmitLine(" return __rep._" + returnMapping.m_fieldName + ";");
1378+
EmitLine($" return __rep._{returnMapping.m_fieldName};");
13791379
}
13801380
}
13811381
}

projects/RabbitMQ.Client/client/api/AmqpTcpEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public override int GetHashCode()
281281
/// </remarks>
282282
public override string ToString()
283283
{
284-
return "amqp://" + HostName + ":" + Port;
284+
return $"amqp://{HostName}:{Port}";
285285
}
286286
}
287287
}

projects/RabbitMQ.Client/client/api/AmqpTimestamp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public AmqpTimestamp(long unixTime) : this()
7979
/// </summary>
8080
public override string ToString()
8181
{
82-
return "((time_t)" + UnixTime + ")";
82+
return $"((time_t){UnixTime})";
8383
}
8484
}
8585
}

projects/RabbitMQ.Client/client/api/ConnectionFactory.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ private void SetUri(Uri uri)
548548
}
549549
else
550550
{
551-
throw new ArgumentException("Wrong scheme in AMQP URI: " + uri.Scheme);
551+
throw new ArgumentException($"Wrong scheme in AMQP URI: {uri.Scheme}");
552552
}
553553
string host = uri.Host;
554554
if (!string.IsNullOrEmpty(host))
@@ -569,7 +569,7 @@ private void SetUri(Uri uri)
569569
string[] userPass = userInfo.Split(':');
570570
if (userPass.Length > 2)
571571
{
572-
throw new ArgumentException("Bad user info in AMQP " + "URI: " + userInfo);
572+
throw new ArgumentException($"Bad user info in AMQP URI: {userInfo}");
573573
}
574574
UserName = UriDecode(userPass[0]);
575575
if (userPass.Length == 2)
@@ -582,9 +582,7 @@ private void SetUri(Uri uri)
582582
that has at least the path segment "/". */
583583
if (uri.Segments.Length > 2)
584584
{
585-
throw new ArgumentException("Multiple segments in " +
586-
"path of AMQP URI: " +
587-
string.Join(", ", uri.Segments));
585+
throw new ArgumentException($"Multiple segments in path of AMQP URI: {string.Join(", ", uri.Segments)}");
588586
}
589587
if (uri.Segments.Length == 2)
590588
{

projects/RabbitMQ.Client/client/api/PlainMechanism.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class PlainMechanism : IAuthMechanism
4646
{
4747
public byte[] handleChallenge(byte[] challenge, IConnectionFactory factory)
4848
{
49-
return Encoding.UTF8.GetBytes("\0" + factory.UserName + "\0" + factory.Password);
49+
return Encoding.UTF8.GetBytes($"\0{factory.UserName}\0{factory.Password}");
5050
}
5151
}
5252
}

projects/RabbitMQ.Client/client/api/PublicationAddress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static bool TryParse(string uriLikeString, out PublicationAddress result)
147147
/// </summary>
148148
public override string ToString()
149149
{
150-
return ExchangeType + "://" + ExchangeName + "/" + RoutingKey;
150+
return $"{ExchangeType}://{ExchangeName}/{RoutingKey}";
151151
}
152152
}
153153
}

projects/RabbitMQ.Client/client/api/ShutdownReportEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public ShutdownReportEntry(string description, Exception exception)
6666

6767
public override string ToString()
6868
{
69-
string output = "Message: " + Description;
70-
return (Exception != null) ? output + " Exception: " + Exception : output;
69+
string description = $"Message: {Description}";
70+
return (Exception != null) ? $"{description} Exception: {Exception}" : description;
7171
}
7272
}
7373
}

projects/RabbitMQ.Client/client/impl/AmqpVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public override int GetHashCode()
110110
/// </remarks>
111111
public override string ToString()
112112
{
113-
return Major + "-" + Minor;
113+
return $"{Major}-{Minor}";
114114
}
115115
}
116116
}

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ public static IDictionary<string, object> DefaultClientProperties()
260260
["version"] = Encoding.UTF8.GetBytes(s_version),
261261
["platform"] = Encoding.UTF8.GetBytes(".NET"),
262262
["copyright"] = Encoding.UTF8.GetBytes("Copyright (c) 2007-2020 VMware, Inc."),
263-
["information"] = Encoding.UTF8.GetBytes("Licensed under the MPL. " +
264-
"See https://www.rabbitmq.com/")
263+
["information"] = Encoding.UTF8.GetBytes("Licensed under the MPL. See https://www.rabbitmq.com/")
265264
};
266265
return table;
267266
}
@@ -335,8 +334,7 @@ public void Close(ShutdownEventArgs reason, bool abort, TimeSpan timeout)
335334
}
336335
else
337336
{
338-
LogCloseError("Couldn't close connection cleanly. "
339-
+ "Socket closed unexpectedly", ioe);
337+
LogCloseError("Couldn't close connection cleanly. Socket closed unexpectedly", ioe);
340338
}
341339
}
342340
}
@@ -378,14 +376,12 @@ public void ClosingLoop()
378376
{
379377
if (_model0.CloseReason == null)
380378
{
381-
LogCloseError("Connection didn't close cleanly. "
382-
+ "Socket closed unexpectedly", eose);
379+
LogCloseError("Connection didn't close cleanly. Socket closed unexpectedly", eose);
383380
}
384381
}
385382
catch (IOException ioe)
386383
{
387-
LogCloseError("Connection didn't close cleanly. "
388-
+ "Socket closed unexpectedly", ioe);
384+
LogCloseError("Connection didn't close cleanly. Socket closed unexpectedly", ioe);
389385
}
390386
catch (Exception e)
391387
{
@@ -447,7 +443,7 @@ public void HandleMainLoopException(ShutdownEventArgs reason)
447443
}
448444

449445
OnShutdown();
450-
LogCloseError("Unexpected connection closure: " + reason, new Exception(reason.ToString()));
446+
LogCloseError($"Unexpected connection closure: {reason}", new Exception(reason.ToString()));
451447
}
452448

453449
public bool HardProtocolExceptionHandler(HardProtocolException hpe)
@@ -470,8 +466,7 @@ public bool HardProtocolExceptionHandler(HardProtocolException hpe)
470466
}
471467
else
472468
{
473-
LogCloseError("Hard Protocol Exception occured "
474-
+ "while closing the connection", hpe);
469+
LogCloseError("Hard Protocol Exception occured while closing the connection", hpe);
475470
}
476471

477472
return false;
@@ -1117,8 +1112,7 @@ void StartAndTune()
11171112
IAuthMechanismFactory mechanismFactory = _factory.AuthMechanismFactory(mechanisms);
11181113
if (mechanismFactory == null)
11191114
{
1120-
throw new IOException("No compatible authentication mechanism found - " +
1121-
"server offered [" + mechanismsString + "]");
1115+
throw new IOException($"No compatible authentication mechanism found - server offered [{mechanismsString}]");
11221116
}
11231117
IAuthMechanism mechanism = mechanismFactory.GetInstance();
11241118
byte[] challenge = null;

0 commit comments

Comments
 (0)