Skip to content

Commit

Permalink
adding helper extensions from aspnet/Razor#715 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
m0sa committed Nov 26, 2018
1 parent 2ad1c90 commit 0d66912
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Razor;

public static class HelperExtensions
{
public static Func<T1, IHtmlContent> Helper<T1>(
this RazorPageBase page,
Func<T1, Func<object, IHtmlContent>> helper
) => p1 => helper(p1)(null);

public static Func<T1, T2, IHtmlContent> Helper<T1, T2>(
this RazorPageBase page,
Func<T1, T2, Func<object, IHtmlContent>> helper
) => (p1, p2) => helper(p1, p2)(null);

public static Func<T1, T2, T3, IHtmlContent> Helper<T1, T2, T3>(
this RazorPageBase page,
Func<T1, T2, T3, Func<object, IHtmlContent>> helper
) => (p1, p2, p3) => helper(p1, p2, p3)(null);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@using System;
@using Microsoft.AspNetCore.Html
@model System.String
@{
var SomeHelper = this.Helper((string s) => @<text>@item</text>);
}
@for (var i = 0; i < 100; i++)
{
@SomeHelper(Model + i.ToString())
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
@model System.String
@for (var i = 0; i < 100; i++)
{
await Html.RenderPartialAsync("HelperPartial_Partial.cshtml", Model + i.ToString());
await Html.RenderPartialAsync("~/Views/HelperPartial_Partial.cshtml", Model + i.ToString());
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
@model System.String
@for (var i = 0; i < 100; i++)
{
Html.RenderPartial("HelperPartial_Partial.cshtml", Model + i.ToString());
Html.RenderPartial("~/Views/HelperPartial_Partial.cshtml", Model + i.ToString());
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ namespace Microsoft.AspNetCore.Mvc.Performance
public class HelperPerformanceBenchmark : RuntimePerformanceBenchmarkBase
{
private Random _rand = new Random();
public HelperPerformanceBenchmark() : base("~/Views/HelperTyped.cshtml", "~/Views/HelperDynamic.cshtml", "~/Views/HelperPartialSync.cshtml", "~/Views/HelperPartialAsync.cshtml")
public HelperPerformanceBenchmark() : base(
"~/Views/HelperTyped.cshtml",
"~/Views/HelperDynamic.cshtml",
"~/Views/HelperPartialSync.cshtml",
"~/Views/HelperPartialAsync.cshtml",
"~/Views/HelperExtensions.cshtml")
{
}

Expand Down

0 comments on commit 0d66912

Please sign in to comment.