protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory) { var reader = readerFactory(); yield return(new Suggestion() { Description = "Change to <code><a></code>", Fixes = new FixAction[] { new RenameElementFix(tagToken, "a", reader.EndTag) } }); if (tagToken.FindAttribute("NavigateUrl") is { } navigateUrl) { yield return(new Suggestion() { Description = "Change <code>NavigateUrl</code> to <code>href</code>", Fixes = new FixAction[] { new RenameAttributeFix(navigateUrl, "a") } }); } }
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory) { var reader = readerFactory(); yield return(new Suggestion() { Description = "Change to <code><dot:GridViewTextColumn></code>", Fixes = new FixAction[] { new RenameElementFix(tagToken, "dot:GridViewTextColumn", reader.EndTag) } }); if (tagToken.FindAttribute("DataField") is { } dataField) { yield return(new Suggestion() { Description = "Change <code>DataField</code> to <code>ValueBinding</code>", Fixes = new FixAction[] { new RenameAttributeFix(dataField, "ValueBinding"), new SetAttributeValueBindingFix(tagToken, "ValueBinding", dataField.GetValue()), } }); } }
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory) { var reader = readerFactory(); var id = tagToken.FindOrGenerateId(); yield return(new Suggestion() { Description = "Change to <code><dot:TextBox></code> and generate a viewmodel property", Fixes = new FixAction[] { new RenameElementFix(tagToken, "dot:TextBox", reader.EndTag), new SetAttributeValueBindingFix(tagToken, "Text", id), new AddViewModelPropertyFix(id, "string") } }); var autoPostBack = tagToken.FindAttribute("AutoPostBack"); if (autoPostBack != null) { var changedEventName = "On" + id + "Changed"; yield return(new Suggestion() { Description = "Add a viewmodel command to handle the text change", Fixes = new FixAction[] { new RemoveAttributeFix(tagToken, autoPostBack), new SetAttributeCommandBindingFix(tagToken, "Changed", changedEventName), new AddViewModelMethodFix(changedEventName, "void", $"// handle {id} property change") } }); } }
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory) { var reader = readerFactory(); var id = tagToken.FindOrGenerateId(); var commandName = "On" + id + "Click"; yield return(new Suggestion() { Description = $"Change to <code><dot:{tagToken.TagNameWithoutPrefix}></code>", Fixes = new FixAction[] { new RenameElementFix(tagToken, "dot:" + tagToken.TagNameWithoutPrefix, reader.EndTag), new SetAttributeCommandBindingFix(tagToken, "Click", commandName), new AddViewModelMethodFix(commandName, "void", $"// handle click on {id} button") } }); var onclick = tagToken.FindAttribute("OnClick"); if (onclick != null) { yield return(new Suggestion() { Description = $"Remove <code>OnClick</code> attribute", Fixes = new FixAction[] { new RemoveAttributeFix(tagToken, onclick) } }); } }
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, AttributeToken attributeToken) { yield return(new Suggestion() { Description = "Change <code>ToolTip</code> to <code>title</code>", Fixes = new FixAction[] { new RenameAttributeFix(attributeToken, "title") } }); }
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory) { var reader = readerFactory(); yield return(new Suggestion() { Description = "Change to <code><dot:Content></code>", Fixes = new FixAction[] { new RenameElementFix(tagToken, "dot:Content", reader.EndTag) } }); }
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, AttributeToken attributeToken) { if (string.Equals(attributeToken.GetValue(), "server", StringComparison.CurrentCultureIgnoreCase)) { yield return(new Suggestion() { Description = @"DotVVM doesn't need <code>runat=""server""</code> attributes.", Fixes = new[] { new RemoveAttributeFix(tagToken, attributeToken) } }); } }
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, AttributeToken attributeToken) { if (attributeToken.GetValue().StartsWith("{value")) { yield break; } var enabledProperty = tagToken.FindOrGenerateId() + "Enabled"; yield return(new Suggestion() { Description = "Add viewmodel property to guide the <code>Enabled</code> state", Fixes = new FixAction[] { new SetAttributeValueBindingFix(tagToken, "Enabled", enabledProperty), new AddViewModelPropertyFix(enabledProperty, "bool") } }); }
private IList <AspxToken> ReadTokens(BeginTagToken beginTag) { var elementTokens = new List <AspxToken> { beginTag }; if (!beginTag.IsSelfClosing) { // read all tags until the end tag var openTags = new Stack <string>(); openTags.Push(beginTag.TagName); var token = GetNextToken(); while (token != null) { elementTokens.Add(token); if (token is BeginTagToken b && !b.IsSelfClosing) { openTags.Push(b.TagName); } else if (token is EndTagToken e) { if (openTags.Contains(e.TagName, StringComparer.CurrentCultureIgnoreCase)) { // ignore closing tags that are not on the stack var lastTag = openTags.Pop(); while (!string.Equals(e.TagName, lastTag, StringComparison.CurrentCultureIgnoreCase) && openTags.Any()) { openTags.Pop(); } } if (!openTags.Any()) { break; } } token = GetNextToken(); }
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory) { var reader = readerFactory(); yield return(new Suggestion() { Description = "Change to <code><dot:UpdateProgress></code>", Fixes = new FixAction[] { new RenameElementFix(tagToken, "dot:UpdateProgress", reader.EndTag) } }); if (reader.Elements.TryGetValue("ContentTemplate", out var contentTemplate)) { yield return(new Suggestion() { Description = "Remove the <code>ContentTemplate</code> wrapper element", Fixes = new FixAction[] { new RemoveTokenFix(contentTemplate[0]), new RemoveTokenFix(contentTemplate[^ 1])
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory) { var reader = readerFactory(); yield return(new Suggestion() { Description = "Change to <code><dot:Repeater></code>", Fixes = new FixAction[] { new RenameElementFix(tagToken, "dot:Repeater", reader.EndTag) } }); if (reader.Elements.TryGetValue("HeaderTemplate", out var headerTemplate)) { yield return(new Suggestion() { Description = "Move <code>HeaderTemplate</code> before the control", Fixes = new FixAction[] { new MoveTokenRangeFix(headerTemplate.ElementAt(1), headerTemplate.Count - 2, tagToken, Placement.Before), new RemoveTokenFix(headerTemplate[0]), new RemoveTokenFix(headerTemplate[^ 1])
protected override IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory) { var reader = readerFactory(); yield return(new Suggestion() { Description = "Change to <code><img></code>", Fixes = new FixAction[] { new RenameElementFix(tagToken, "img", reader.EndTag) } }); if (tagToken.FindAttribute("ImageUrl") is { } imageUrl) { yield return(new Suggestion() { Description = "Change <code>ImageUrl</code> to <code>src</code>", Fixes = new FixAction[] { new RenameAttributeFix(imageUrl, "src") } }); } if (tagToken.FindAttribute("AlternateText") is { } alternateText) { yield return(new Suggestion() { Description = "Change <code>AlternateText</code> to <code>alt</code>", Fixes = new FixAction[] { new RenameAttributeFix(alternateText, "alt") } }); } }
public RemoveAttributeFix(BeginTagToken tag, AttributeToken attribute) { Tag = tag; Attribute = attribute; }
public RenameElementFix(BeginTagToken tag, string newName, EndTagToken endTag = null) { Tag = tag; NewName = newName; EndTag = endTag; }
public SetAttributeCommandBindingFix(BeginTagToken tag, string name, string commandName) { Tag = tag; Name = name; CommandName = commandName; }
protected abstract IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, AttributeToken attributeToken);
public SetAttributeValueBindingFix(BeginTagToken tag, string name, string viewModelProperty) { Tag = tag; Name = name; ViewModelProperty = viewModelProperty; }
protected abstract IEnumerable <Suggestion> TryProvideSuggestions(BeginTagToken tagToken, Func <ControlInnerElementsReader> readerFactory);