Here's the current code:
static string GetResources(string header, string filter, string resourceTemplate)
{
string themeName;
if (!TryGetHeaderValue(header, "theme", out themeName)) return "";
var resources = "";
var path = Path.Combine(HtmlPreview.BaseDirectory, themeName);
foreach (var resource in Directory.GetFiles(path, filter))
{
resources += String.Format(
resourceTemplate,
themeName,
Path.GetFileName(resource));
}
return resources;
}
I was wondering if I should use string builder instead:
static string GetResources(string header, string filter, string resourceTemplate)
{
string themeName;
if (!TryGetHeaderValue(header, "theme", out themeName)) return "";
var resourcesStringBuilder = new StringBuilder();
var path = Path.Combine(HtmlPreview.BaseDirectory, themeName);
foreach (var resource in Directory.GetFiles(path, filter))
{
resourcesStringBuilder.Append(String.Format(
resourceTemplate,
themeName,
Path.GetFileName(resource)));
}
return resourcesStringBuilder.ToString();
}
Resharper simply suggests it is possible to replace the original code with a LINQ statement:
static string GetResources(string header, string filter, string resourceTemplate)
{
string themeName;
if (!TryGetHeaderValue(header, "theme", out themeName)) return "";
var path = Path.Combine(HtmlPreview.BaseDirectory, themeName);
return Directory.GetFiles(path, filter)
.Aggregate("",
(current, resource) => current +
String.Format(resourceTemplate,
themeName,
Path.GetFileName(resource)));
}
Thank you! The original code with context is also on github.