-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from StuffOfInterest/feature-while
Feature while
- Loading branch information
Showing
11 changed files
with
162 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,10 @@ public IActionResult TestForeach() | |
{ | ||
return View(); | ||
} | ||
|
||
public IActionResult TestWhile() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h2>Test 1</h2> | ||
|
||
@{ var x = 0; } | ||
<while condition="() => x < 10"> | ||
<p>Should display @x.</p> | ||
@{ x++; } | ||
</while> | ||
|
||
<h2>Test 2</h2> | ||
|
||
@try | ||
{ | ||
<while> | ||
<p>Should not display.</p> | ||
</while> | ||
} | ||
catch (Exception ex) | ||
{ | ||
<p>Expected exception occurred: '@ex.Message'.</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace LogicTagHelpers | ||
{ | ||
/// <summary> | ||
/// Re-render block of code as long as condition evaluates to true. | ||
/// </summary> | ||
public class WhileTagHelper : TagHelper | ||
{ | ||
/// <summary> | ||
/// Function to evaluate exit condition. | ||
/// Inner content will render as long as the condition returns true. | ||
/// </summary> | ||
public Func<bool> Condition { get; set; } | ||
|
||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
if (Condition == null) | ||
{ | ||
throw new LogicTagHelperException("Condition may not be null."); | ||
} | ||
|
||
output.TagName = null; | ||
output.Content.Clear(); | ||
|
||
while (Condition.Invoke()) | ||
{ | ||
var childContent = await output.GetChildContentAsync(false); | ||
output.Content.AppendHtml(childContent); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters