mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-24 05:42:10 +08:00
Use string.Join instead of obscure and inefficient Aggregate pattern
CultureCommand change actually fixes a benign bug in one of the commands (extra space at the end). DisplayHelper is clarified by better typing of intermediate results.
This commit is contained in:
@@ -49,7 +49,7 @@ namespace Orchard.Tests {
|
||||
|
||||
public static ISessionFactory CreateSessionFactory(params Type[] types) {
|
||||
return CreateSessionFactory(
|
||||
types.Aggregate("db", (n, t) => t.FullName + "." + n),
|
||||
string.Join(".", types.Reverse().Select(type => type.FullName)),
|
||||
types);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,11 +76,11 @@ namespace Orchard.Widgets.Commands {
|
||||
[CommandHelp("widget create <type> /Title:<title> /Name:<name> /Zone:<zone> /Position:<position> /Layer:<layer> [/Identity:<identity>] [/RenderTitle:true|false] [/Owner:<owner>] [/Text:<text>] [/UseLoremIpsumText:true|false] [/MenuName:<name>]\r\n\t" + "Creates a new widget")]
|
||||
[OrchardSwitches("Title,Name,Zone,Position,Layer,Identity,Owner,Text,UseLoremIpsumText,MenuName,RenderTitle")]
|
||||
public void Create(string type) {
|
||||
var widgetTypeNames = _widgetsService.GetWidgetTypeNames();
|
||||
var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();
|
||||
if (!widgetTypeNames.Contains(type)) {
|
||||
Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
|
||||
type,
|
||||
widgetTypeNames.Aggregate(String.Empty, (current, widgetType) => current + " " + widgetType)));
|
||||
string.Join(" ", widgetTypeNames)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,31 +53,31 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
}
|
||||
|
||||
public class Combined : IHtmlString {
|
||||
private readonly IEnumerable<object> _fragments;
|
||||
private readonly IEnumerable<IHtmlString> _fragments;
|
||||
|
||||
public Combined(IEnumerable<object> fragments) {
|
||||
public Combined(IEnumerable<IHtmlString> fragments) {
|
||||
_fragments = fragments;
|
||||
}
|
||||
|
||||
public string ToHtmlString() {
|
||||
return _fragments.Aggregate("", (a, b) => a + b);
|
||||
return string.Join("", _fragments);
|
||||
}
|
||||
public override string ToString() {
|
||||
return ToHtmlString();
|
||||
}
|
||||
}
|
||||
|
||||
private object ShapeTypeExecute(string name, INamedEnumerable<object> parameters) {
|
||||
private IHtmlString ShapeTypeExecute(string name, INamedEnumerable<object> parameters) {
|
||||
var shape = _shapeFactory.Create(name, parameters);
|
||||
return ShapeExecute(shape);
|
||||
}
|
||||
|
||||
public object ShapeExecute(Shape shape) {
|
||||
public IHtmlString ShapeExecute(Shape shape) {
|
||||
// disambiguates the call to ShapeExecute(object) as Shape also implements IEnumerable
|
||||
return ShapeExecute((object) shape);
|
||||
}
|
||||
|
||||
public object ShapeExecute(object shape) {
|
||||
public IHtmlString ShapeExecute(object shape) {
|
||||
if (shape == null) {
|
||||
return new HtmlString(string.Empty);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ namespace Orchard.DisplayManagement.Implementation {
|
||||
return _displayManager.Execute(context);
|
||||
}
|
||||
|
||||
public IEnumerable<object> ShapeExecute(IEnumerable<object> shapes) {
|
||||
public IEnumerable<IHtmlString> ShapeExecute(IEnumerable<object> shapes) {
|
||||
return shapes.Select(ShapeExecute).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Orchard.Localization.Commands {
|
||||
public void ListCultures() {
|
||||
Context.Output.WriteLine(T("Listing Cultures:"));
|
||||
|
||||
string cultures = _cultureManager.ListCultures().Aggregate<string, string>(null, (current, culture) => current + culture + " ");
|
||||
var cultures = string.Join(" ", _cultureManager.ListCultures());
|
||||
|
||||
Context.Output.WriteLine(cultures);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace Orchard.Utility {
|
||||
}
|
||||
|
||||
AddNames(callExpression.Object, nb);
|
||||
nb.Append("[" + GetArguments(callExpression.Arguments).Aggregate((a, b) => a + b) + "]");
|
||||
nb.Append("[" + string.Join("", GetArguments(callExpression.Arguments)) + "]");
|
||||
break;
|
||||
|
||||
case ExpressionType.Parameter:
|
||||
|
||||
Reference in New Issue
Block a user