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
output.Content.SetHtmlContent( | |
$"<img src=\"images/{handContext.Player}.png\" alt=\"avatar\" class=\"center-block\" /><div class=\"text-center\"><h2 class=\"{suitAttributes.colorClass}\"><strong>{suitAttributes.characterCode}</strong></h2><p>{Rank}</p></div>"); |
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
// Fetch the context, so that we can get the player name to display the appropriate image | |
var handContext = (HandContext)context.Items[typeof(HandTagHelper)]; | |
var playerName = handContext.Player; |
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
public class HandContext | |
{ | |
public string Player { get; set; } | |
} | |
[HtmlTargetElement(Constants.HAND_TAG_HELPER_ELEMENT_NAME, Attributes = nameof(Player), TagStructure = TagStructure.NormalOrSelfClosing)] | |
[RestrictChildren(Constants.CARD_TAG_HELPER_ELEMENT_NAME)] | |
public class HandTagHelper : TagHelper | |
{ | |
public string Player { get; set; } |
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
<hand> | |
<card suit="Spade" rank="Queen"></card> <!-- TagHelper --> | |
<card rank="Queen"></card> <!-- Not a TagHelper --> | |
<card suit="Spade"></card> <!-- Not a TagHelper --> | |
</hand> |
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
[HtmlTargetElement("card", ParentTag = "hand", Attributes = nameof(Suit) + "," + nameof(Rank), TagStructure = TagStructure.NormalOrSelfClosing)] | |
public class CardTagHelper : TagHelper | |
{ | |
public string Rank { get; set; } | |
public string Suit { get; set; } | |
} |
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
<hand> | |
<card suit="Diamond"></card> <!-- TagHelper --> | |
<card rank="Four"></card> <!-- TagHelper --> | |
<card></card> <!-- Not a TagHelper --> | |
</hand> |
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
[HtmlTargetElement("card", ParentTag = "hand", Attributes = nameof(Suit), TagStructure = TagStructure.NormalOrSelfClosing)] | |
[HtmlTargetElement("card", ParentTag = "hand", Attributes = nameof(Rank), TagStructure = TagStructure.NormalOrSelfClosing)] | |
public class CardTagHelper : TagHelper | |
{ | |
public string Rank { get; set; } | |
public string Suit { get; set; } | |
} |
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
@using static TagHelpersDemo.TagHelpers.CardTagHelper | |
@{ | |
ViewData["Title"] = "Home Page"; | |
} | |
<div class="clearfix"> </div> | |
<hand player="John"> | |
<card suit="@CardSuit.Heart" rank="@CardRank.Ace"></card> |
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
<PropertyGroup> | |
<IsLocalDev>true</IsLocalDev> | |
</PropertyGroup> | |
<Target Name="BeforeBuild" Condition="$(IsLocalDev) == true"> | |
<Exec Command="CodeFormatter $(MSBuildProjectFile) /rule+:BraceNewLine,UsingLocation,FormatDocument,NewLineAbove /rule-:Copyright,CustomCopyright,UnicodeLiterals,ExplicitVisibility,IllegalHeaders,ExplicitThis,ReadonlyFields,FieldNames /verbose" | |
ContinueOnError="false" /> | |
</Target> |
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
<Target Name="BeforeBuild"> | |
<Exec Command="CodeFormatter $(MSBuildProjectFile) /rule+:BraceNewLine,UsingLocation,FormatDocument,NewLineAbove /rule-:Copyright,CustomCopyright,UnicodeLiterals,ExplicitVisibility,IllegalHeaders,ExplicitThis,ReadonlyFields,FieldNames /verbose" | |
ContinueOnError="false" /> | |
</Target> |