mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Removing ShapeBinding delegate type in favor of Func<DisplayContext, IHtmlString>
Was slightly confusing - no other delegates are typed, making the named ShapeBinding look like a class. --HG-- branch : mvc3p1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
@@ -24,10 +25,9 @@ namespace Orchard.DisplayManagement.Descriptors {
|
||||
|
||||
public class ShapeDescriptor {
|
||||
public string ShapeType { get; set; }
|
||||
public ShapeBinding Binding { get; set; }
|
||||
public Func<DisplayContext, IHtmlString> Binding { get; set; }
|
||||
}
|
||||
|
||||
public delegate object ShapeBinding(DisplayContext displayContext);
|
||||
|
||||
public class ShapeTableBuilder {
|
||||
readonly IList<ShapeDescriptorAlterationBuilderImpl> _descriptorBuilders = new List<ShapeDescriptorAlterationBuilderImpl>();
|
||||
@@ -89,11 +89,11 @@ namespace Orchard.DisplayManagement.Descriptors {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShapeDescriptorAlterationBuilder BoundAs(Func<ShapeDescriptor, ShapeBinding> binder) {
|
||||
public ShapeDescriptorAlterationBuilder BoundAs(Func<ShapeDescriptor, Func<DisplayContext, IHtmlString>> binder) {
|
||||
// schedule the configuration
|
||||
return Configure(descriptor => {
|
||||
|
||||
ShapeBinding target = null;
|
||||
|
||||
Func<DisplayContext, IHtmlString> target = null;
|
||||
|
||||
// announce the binding, which may be reconfigured before it's used
|
||||
descriptor.Binding = displayContext => {
|
||||
|
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
using Microsoft.CSharp.RuntimeBinder;
|
||||
@@ -34,7 +35,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
private ShapeBinding CreateDelegate(
|
||||
private Func<DisplayContext, IHtmlString> CreateDelegate(
|
||||
ShapeAttributeOccurrence attributeOccurrence,
|
||||
ShapeDescriptor descriptor) {
|
||||
return context => {
|
||||
@@ -46,11 +47,15 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
}
|
||||
|
||||
|
||||
private object PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance) {
|
||||
private IHtmlString PerformInvoke(DisplayContext displayContext, MethodInfo methodInfo, object serviceInstance) {
|
||||
var arguments = methodInfo.GetParameters()
|
||||
.Select(parameter => BindParameter(displayContext, parameter));
|
||||
|
||||
return methodInfo.Invoke(serviceInstance, arguments.ToArray());
|
||||
return CoerceHtmlString(methodInfo.Invoke(serviceInstance, arguments.ToArray()));
|
||||
}
|
||||
|
||||
private static IHtmlString CoerceHtmlString(object invoke) {
|
||||
return invoke as IHtmlString ?? (invoke != null ? new HtmlString(invoke.ToString()) : null);
|
||||
}
|
||||
|
||||
private object BindParameter(DisplayContext displayContext, ParameterInfo parameter) {
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
@@ -79,7 +80,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
private object Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
|
||||
private IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
|
||||
var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
|
||||
//return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
|
||||
return htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath.Replace("\\", "/") + ".cshtml", displayContext.Value);
|
||||
|
Reference in New Issue
Block a user