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;

BlogEngine/BlogEngine.Core/Data/PackageRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public bool Update(Package item)
129129
}
130130
else
131131
{
132-
Utils.Log(string.Format("Failed to find extension {0} while trying to update package repository", item.Id));
132+
Utils.Log($"Failed to find extension {item.Id} while trying to update package repository");
133133
}
134134
}
135135
break;

BlogEngine/BlogEngine.Core/Data/PageRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static string GetUniqueSlug(string slug)
182182
if (IsUniqueSlug(s))
183183
break;
184184

185-
s = string.Format("{0}{1}", slug, i);
185+
s = $"{slug}{i}";
186186
}
187187
return s;
188188
}

BlogEngine/BlogEngine.Core/Data/PostRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static string GetUniqueSlug(string slug)
226226
if (IsUniqueSlug(s))
227227
break;
228228

229-
s = string.Format("{0}{1}", slug, i);
229+
s = $"{slug}{i}";
230230
}
231231
return s;
232232
}

BlogEngine/BlogEngine.Core/Data/Services/Avatar.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace BlogEngine.Core.Data.Services
1010
/// </summary>
1111
public class Avatar
1212
{
13-
private static string _noAvatar = string.Format("{0}Content/images/blog/noavatar.jpg", Utils.AbsoluteWebRoot);
14-
private static string _pingImg = string.Format("{0}Content/images/blog/pingback.png", Utils.AbsoluteWebRoot);
13+
private static string _noAvatar = $"{Utils.AbsoluteWebRoot}Content/images/blog/noavatar.jpg";
14+
private static string _pingImg = $"{Utils.AbsoluteWebRoot}Content/images/blog/pingback.png";
1515

1616
/// <summary>
1717
/// Get avatar image source
@@ -43,13 +43,13 @@ public static string GetSrc(string email, string website = "")
4343
return src;
4444

4545
// default noavatar if nothing worked
46-
return string.Format("{0}Content/images/blog/noavatar.jpg", Utils.AbsoluteWebRoot);
46+
return $"{Utils.AbsoluteWebRoot}Content/images/blog/noavatar.jpg";
4747
}
4848

4949
static string ThemeNoAvatar(string email)
5050
{
51-
var themeAvatar = string.Format(
52-
"{0}Custom/Themes/{1}/noavatar.jpg", Utils.ApplicationRelativeWebRoot, BlogSettings.Instance.Theme);
51+
var themeAvatar =
52+
$"{Utils.ApplicationRelativeWebRoot}Custom/Themes/{BlogSettings.Instance.Theme}/noavatar.jpg";
5353

5454
if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(themeAvatar)))
5555
return themeAvatar;
@@ -65,7 +65,7 @@ static string Gravatar(string email)
6565
if (hash != null)
6666
hash = hash.ToLowerInvariant();
6767

68-
var gravatar = string.Format("http://www.gravatar.com/avatar/{0}.jpg?d=", hash);
68+
var gravatar = $"http://www.gravatar.com/avatar/{hash}.jpg?d=";
6969

7070
switch (BlogSettings.Instance.Avatar)
7171
{

BlogEngine/BlogEngine.Core/Data/Services/CustomFieldsParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static List<CustomField> LoadFields()
159159
static List<CustomField> FromThemeTemplates()
160160
{
161161
var dirPath = HttpContext.Current.Server.MapPath(
162-
string.Format("{0}Custom/Themes", Utils.ApplicationRelativeWebRoot));
162+
$"{Utils.ApplicationRelativeWebRoot}Custom/Themes");
163163

164164
var items = new List<CustomField>();
165165

BlogEngine/BlogEngine.Core/Data/Services/TagCloud.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public List<string> Links()
3434
{
3535
var link = string.Format(
3636
Link,
37-
string.Format("{0}?tag={1}", Utils.AbsoluteWebRoot, HttpUtility.UrlEncode(key)),
38-
WeightedList[key], string.Format("Tag: {0}", key), key);
37+
$"{Utils.AbsoluteWebRoot}?tag={HttpUtility.UrlEncode(key)}",
38+
WeightedList[key], $"Tag: {key}", key);
3939
links.Add(link);
4040
}
4141
return links;

BlogEngine/BlogEngine.Core/Data/TagRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public bool Save(string updateFrom, string updateTo)
8787
}
8888
catch (Exception ex)
8989
{
90-
Utils.Log(string.Format("TagRepository.Update: {0}", ex.Message));
90+
Utils.Log($"TagRepository.Update: {ex.Message}");
9191
return false;
9292
}
9393
}
@@ -117,7 +117,7 @@ public bool Delete(string id)
117117
}
118118
catch (Exception ex)
119119
{
120-
Utils.Log(string.Format("Tags.Delete: {0}", ex.Message));
120+
Utils.Log($"Tags.Delete: {ex.Message}");
121121
return false;
122122
}
123123
}

BlogEngine/BlogEngine.Core/Helpers/BlogGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static bool CopyTemplateBlogFolder(string blogName, string userName, stri
150150

151151
if (!Directory.Exists(templateFolderPath))
152152
{
153-
throw new Exception(string.Format("Template folder for new blog does not exist. Directory not found is: {0}", templateFolderPath));
153+
throw new Exception($"Template folder for new blog does not exist. Directory not found is: {templateFolderPath}");
154154
}
155155
}
156156
catch (Exception ex)
@@ -165,7 +165,7 @@ public static bool CopyTemplateBlogFolder(string blogName, string userName, stri
165165
{
166166
if (Directory.Exists(newBlogFolderPath))
167167
{
168-
throw new Exception(string.Format("Blog destination folder already exists. {0}", newBlogFolderPath));
168+
throw new Exception($"Blog destination folder already exists. {newBlogFolderPath}");
169169
}
170170
}
171171
catch (Exception ex)
@@ -174,7 +174,7 @@ public static bool CopyTemplateBlogFolder(string blogName, string userName, stri
174174
throw; // re-throw error so error message bubbles up.
175175
}
176176
if (!Utils.CreateDirectoryIfNotExists(newBlogFolderPath))
177-
throw new Exception(string.Format("Can not create blog directory: {0}", newBlogFolderPath));
177+
throw new Exception($"Can not create blog directory: {newBlogFolderPath}");
178178

179179
// Copy the entire directory contents.
180180
DirectoryInfo source = new DirectoryInfo(templateFolderPath);

BlogEngine/BlogEngine.Core/Helpers/Pager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static string Render(string callback = "false")
100100

101101
var linkFormat = "<a href=\"#\" id=\"{0}\" onclick=\"return " + callback + ";\" class=\"{0}\">{1}</a>";
102102

103-
var pageLink = string.Format("<span>Showing {0} - {1} of {2}</span>", From, To, Total);
103+
var pageLink = $"<span>Showing {From} - {To} of {Total}</span>";
104104

105105
if (CurrentPage > 1)
106106
{

0 commit comments

Comments
 (0)