mirror of https://github.com/abpframework/abp.git
17 changed files with 219 additions and 136 deletions
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using System.Reflection; |
|||
using Microsoft.AspNetCore.Mvc.ViewFeatures; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions |
|||
{ |
|||
public static class ModelExplorerExtensions |
|||
{ |
|||
public static T GetAttribute<T>(this ModelExplorer property) where T : Attribute |
|||
{ |
|||
return property?.Metadata?.ContainerType?.GetTypeInfo()?.GetProperty(property.Metadata.PropertyName)?.GetCustomAttribute<T>(); |
|||
} |
|||
|
|||
public static int GetDisplayOrder(this ModelExplorer explorer) |
|||
{ |
|||
return GetAttribute<DisplayOrder>(explorer)?.Number ?? DisplayOrder.Default; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions |
|||
{ |
|||
public static class TagHelperContextExtensions |
|||
{ |
|||
public static T GetValue<T>(this TagHelperContext context, string key) |
|||
{ |
|||
if (!context.Items.ContainsKey(key)) |
|||
{ |
|||
return default(T); |
|||
} |
|||
|
|||
return (T)context.Items[key]; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using System.Text.Encodings.Web; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions |
|||
{ |
|||
public static class TagHelperExtensions |
|||
{ |
|||
public static TagHelperOutput GetTagHelperOutput(this TagHelper tagHelper, TagHelperAttributeList attributeList, TagHelperContext context, string tagName = "div", TagMode tagMode = TagMode.SelfClosing, bool runAsync = false) |
|||
{ |
|||
var innerOutput = new TagHelperOutput(tagName, attributeList, (useCachedResult, encoder) => Task.Run<TagHelperContent>(() => new DefaultTagHelperContent())) |
|||
{ |
|||
TagMode = tagMode |
|||
}; |
|||
|
|||
var innerContext = new TagHelperContext(attributeList, context.Items, Guid.NewGuid().ToString()); |
|||
|
|||
tagHelper.Init(context); |
|||
|
|||
if (runAsync) |
|||
{ |
|||
AsyncHelper.RunSync(() => tagHelper.ProcessAsync(innerContext, innerOutput)); |
|||
} |
|||
else |
|||
{ |
|||
tagHelper.Process(innerContext, innerOutput); |
|||
} |
|||
|
|||
return innerOutput; |
|||
} |
|||
|
|||
public static string Render(this TagHelper tagHelper, TagHelperAttributeList attributeList, TagHelperContext context, HtmlEncoder htmlEncoder, string tagName = "div", TagMode tagMode = TagMode.SelfClosing, bool runAsync = false) |
|||
{ |
|||
var innerOutput = tagHelper.GetTagHelperOutput(attributeList, context, tagName, tagMode, runAsync); |
|||
|
|||
return innerOutput.Render(htmlEncoder); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using System.IO; |
|||
using System.Text.Encodings.Web; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions |
|||
{ |
|||
public static class TagHelperOutputExtensions |
|||
{ |
|||
public static string Render(this TagHelperOutput output, HtmlEncoder htmlEncoder) |
|||
{ |
|||
using (var writer = new StringWriter()) |
|||
{ |
|||
output.WriteTo(writer, htmlEncoder); |
|||
return writer.ToString(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue