Skip to content

Commit a7902cd

Browse files
author
ThisWillDoIt
committed
introduced string interpolation where it could simplify the code
1 parent caecc31 commit a7902cd

File tree

105 files changed

+391
-421
lines changed

Some content is hidden

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

105 files changed

+391
-421
lines changed

BlogEngine/BlogEngine.Core/API/MetaWeblog/MetaWeblogHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ internal bool DeletePage(string blogId, string pageId, string userName, string p
177177
}
178178
catch (Exception ex)
179179
{
180-
throw new MetaWeblogException("15", string.Format("DeletePage failed. Error: {0}", ex.Message));
180+
throw new MetaWeblogException("15", $"DeletePage failed. Error: {ex.Message}");
181181
}
182182

183183
return true;
@@ -220,7 +220,7 @@ internal bool DeletePost(string appKey, string postId, string userName, string p
220220
}
221221
catch (Exception ex)
222222
{
223-
throw new MetaWeblogException("12", string.Format("DeletePost failed. Error: {0}", ex.Message));
223+
throw new MetaWeblogException("12", $"DeletePost failed. Error: {ex.Message}");
224224
}
225225

226226
return true;
@@ -712,7 +712,7 @@ internal MWAMediaInfo NewMediaObject(
712712

713713
var mediaInfo = new MWAMediaInfo();
714714

715-
var rootPath = string.Format("{0}files/", Blog.CurrentInstance.StorageLocation);
715+
var rootPath = $"{Blog.CurrentInstance.StorageLocation}files/";
716716
var serverPath = request.Server.MapPath(rootPath);
717717
var saveFolder = serverPath;
718718
string mediaObjectName = mediaObject.name.Replace(" ", "_");
@@ -749,7 +749,7 @@ internal MWAMediaInfo NewMediaObject(
749749
// Find unique fileName
750750
for (var count = 1; count < 30000; count++)
751751
{
752-
var tempFileName = fileName.Insert(fileName.LastIndexOf('.'), string.Format("_{0}", count));
752+
var tempFileName = fileName.Insert(fileName.LastIndexOf('.'), $"_{count}");
753753
if (File.Exists(saveFolder + tempFileName))
754754
{
755755
continue;

BlogEngine/BlogEngine.Core/API/MetaWeblog/XMLRPCRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private void LoadXmlRequest(string xml)
339339
}
340340
catch (Exception ex)
341341
{
342-
throw new MetaWeblogException("01", string.Format("Invalid XMLRPC Request. ({0})", ex.Message));
342+
throw new MetaWeblogException("01", $"Invalid XMLRPC Request. ({ex.Message})");
343343
}
344344

345345
// Method name is always first
@@ -449,7 +449,7 @@ private void LoadXmlRequest(string xml)
449449
this.PageID = this.inputParams[3].InnerText;
450450
break;
451451
default:
452-
throw new MetaWeblogException("02", string.Format("Unknown Method. ({0})", this.MethodName));
452+
throw new MetaWeblogException("02", $"Unknown Method. ({MethodName})");
453453
}
454454
}
455455

BlogEngine/BlogEngine.Core/AuthorProfile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public string FullName
300300
{
301301
get
302302
{
303-
return string.Format("{0} {1} {2}", this.FirstName, this.MiddleName, this.LastName).Replace(" ", " ");
303+
return $"{FirstName} {MiddleName} {LastName}".Replace(" ", " ");
304304
}
305305
}
306306

@@ -439,7 +439,7 @@ public string RelativeLink
439439
{
440440
get
441441
{
442-
return string.Format("{0}author/{1}{2}", Utils.RelativeWebRoot, this.Id, BlogConfig.FileExtension);
442+
return $"{Utils.RelativeWebRoot}author/{Id}{BlogConfig.FileExtension}";
443443
}
444444
}
445445

BlogEngine/BlogEngine.Core/Blog.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public string StorageLocation
629629
return BlogConfig.StorageLocation;
630630
}
631631

632-
return string.Format("{0}{1}/{2}/", BlogConfig.StorageLocation, BlogConfig.BlogInstancesFolderName, this.StorageContainerName);
632+
return $"{BlogConfig.StorageLocation}{BlogConfig.BlogInstancesFolderName}/{StorageContainerName}/";
633633
}
634634
}
635635

@@ -676,7 +676,7 @@ public Uri AbsoluteWebRoot
676676
{
677677
get
678678
{
679-
string contextItemKey = string.Format("{0}-absolutewebroot", this.Id);
679+
string contextItemKey = $"{Id}-absolutewebroot";
680680

681681
var context = HttpContext.Current;
682682
if (context == null)
@@ -955,7 +955,7 @@ internal bool CopyExistingBlogFolderToNewBlogFolder(Blog existingBlog)
955955
existingBlogStoragePath = HostingEnvironment.MapPath(existingBlog.StorageLocation);
956956
if (!Directory.Exists(existingBlogStoragePath))
957957
{
958-
throw new Exception(string.Format("Storage folder for existing blog instance to copy from does not exist. Directory not found is: {0}", existingBlogStoragePath));
958+
throw new Exception($"Storage folder for existing blog instance to copy from does not exist. Directory not found is: {existingBlogStoragePath}");
959959
}
960960
}
961961
catch (Exception ex)
@@ -965,7 +965,7 @@ internal bool CopyExistingBlogFolderToNewBlogFolder(Blog existingBlog)
965965
}
966966

967967
// Ensure "BlogInstancesFolderName" exists.
968-
string blogInstancesFolder = HostingEnvironment.MapPath(string.Format("{0}{1}", BlogConfig.StorageLocation, BlogConfig.BlogInstancesFolderName));
968+
string blogInstancesFolder = HostingEnvironment.MapPath($"{BlogConfig.StorageLocation}{BlogConfig.BlogInstancesFolderName}");
969969
if (!Utils.CreateDirectoryIfNotExists(blogInstancesFolder))
970970
return false;
971971

@@ -976,7 +976,7 @@ internal bool CopyExistingBlogFolderToNewBlogFolder(Blog existingBlog)
976976
{
977977
if (Directory.Exists(newBlogStoragePath))
978978
{
979-
throw new Exception(string.Format("Blog destination folder already exists. {0}", newBlogStoragePath));
979+
throw new Exception($"Blog destination folder already exists. {newBlogStoragePath}");
980980
}
981981
}
982982
catch (Exception ex)

BlogEngine/BlogEngine.Core/BlogSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public bool IsRazorTheme
149149
/// </summary>
150150
public static bool IsThemeRazor(string themeName)
151151
{
152-
string path = HostingEnvironment.MapPath(string.Format("~/Custom/Themes/{0}/site.cshtml", themeName));
152+
string path = HostingEnvironment.MapPath($"~/Custom/Themes/{themeName}/site.cshtml");
153153
return File.Exists(path);
154154
}
155155

@@ -1312,7 +1312,7 @@ private void Load(Blog blog)
13121312
}
13131313
catch (Exception e)
13141314
{
1315-
Utils.Log(string.Format("Error loading blog settings: {0}", e.Message));
1315+
Utils.Log($"Error loading blog settings: {e.Message}");
13161316
}
13171317
}
13181318

BlogEngine/BlogEngine.Core/Category.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public string CompleteTitle()
366366

367367
var cat = GetCategory((Guid)parent, Blog.CurrentInstance.IsSiteAggregation);
368368

369-
return cat == null ? title : string.Format("{0} - {1}", cat.CompleteTitle(), title);
369+
return cat == null ? title : $"{cat.CompleteTitle()} - {title}";
370370
}
371371

372372

BlogEngine/BlogEngine.Core/Comment.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public Uri AbsoluteLink
6969
{
7070
get
7171
{
72-
return new Uri(string.Format("{0}#id_{1}", Parent.AbsoluteLink, Id));
72+
return new Uri($"{Parent.AbsoluteLink}#id_{Id}");
7373
}
7474
}
7575

@@ -240,7 +240,7 @@ public string RelativeLink
240240
{
241241
get
242242
{
243-
return string.Format("{0}#id_{1}", Parent.RelativeLink, Id);
243+
return $"{Parent.RelativeLink}#id_{Id}";
244244
}
245245
}
246246

@@ -268,7 +268,7 @@ public string Teaser
268268
get
269269
{
270270
var ret = Utils.StripHtml(Content).Trim();
271-
return ret.Length > 120 ? string.Format("{0} ...", ret.Substring(0, 116)) : ret;
271+
return ret.Length > 120 ? $"{ret.Substring(0, 116)} ..." : ret;
272272
}
273273
}
274274

BlogEngine/BlogEngine.Core/Data/CategoryRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public CategoryItem Add(CategoryItem item)
115115
}
116116
catch (Exception ex)
117117
{
118-
Utils.Log(string.Format("CategoryRepository.Add: {0}", ex.Message));
118+
Utils.Log($"CategoryRepository.Add: {ex.Message}");
119119
return null;
120120
}
121121
}
@@ -172,7 +172,7 @@ public bool Remove(Guid id)
172172
}
173173
catch (Exception ex)
174174
{
175-
Utils.Log(string.Format("CategoryRepository.Remove: {0}", ex.Message));
175+
Utils.Log($"CategoryRepository.Remove: {ex.Message}");
176176
return false;
177177
}
178178
}

BlogEngine/BlogEngine.Core/Data/CustomFilterRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ public JsonResponse ResetCounters(string filterName)
8181
}
8282
ExtensionManager.SaveSettings("MetaExtension", CustomFilters);
8383
}
84-
return new JsonResponse() { Success = true, Message = string.Format("Counters for {0} reset", filterName) };
84+
return new JsonResponse() { Success = true, Message = $"Counters for {filterName} reset"};
8585
}
8686
catch (Exception ex)
8787
{
88-
Utils.Log(string.Format("CustomFilterRepository.ResetCounters: {0}", ex.Message));
88+
Utils.Log($"CustomFilterRepository.ResetCounters: {ex.Message}");
8989
return new JsonResponse() { Message = "Error resetting counters" };
9090
}
9191
}

BlogEngine/BlogEngine.Core/Data/LookupsRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void LoadCultures()
7272
}
7373
else
7474
{
75-
var path = HostingEnvironment.MapPath(string.Format("{0}App_GlobalResources/", Utils.ApplicationRelativeWebRoot));
75+
var path = HostingEnvironment.MapPath($"{Utils.ApplicationRelativeWebRoot}App_GlobalResources/");
7676
foreach (var file in Directory.GetFiles(path, "labels.*.resx"))
7777
{
7878
var index = file.LastIndexOf(Path.DirectorySeparatorChar) + 1;

0 commit comments

Comments
 (0)