In RazorCompiler, support @using statements
This commit is contained in:
parent
7cd5228b7f
commit
946e25462e
|
|
@ -244,7 +244,7 @@ namespace Microsoft.Blazor.Build.Core.RazorCompilation.Engine
|
|||
|
||||
public override void WriteUsingDirective(CodeRenderingContext context, UsingDirectiveIntermediateNode node)
|
||||
{
|
||||
throw new System.NotImplementedException(nameof(WriteUsingDirective));
|
||||
context.CodeWriter.WriteUsing(node.Content, endLine: true);
|
||||
}
|
||||
|
||||
private static string GetContent(HtmlContentIntermediateNode node)
|
||||
|
|
|
|||
|
|
@ -286,6 +286,23 @@ namespace Microsoft.Blazor.Build.Test
|
|||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SupportsUsingStatements()
|
||||
{
|
||||
// Arrange
|
||||
var treeBuilder = new RenderTreeBuilder(new TestRenderer());
|
||||
|
||||
// Arrange/Act
|
||||
var component = CompileToComponent(@"
|
||||
@using System.Collections.Generic
|
||||
@(typeof(List<string>).FullName)");
|
||||
component.BuildRenderTree(treeBuilder);
|
||||
|
||||
// Assert
|
||||
Assert.Collection(treeBuilder.GetNodes().Where(NotWhitespace),
|
||||
node => AssertNode.Text(node, typeof(List<string>).FullName));
|
||||
}
|
||||
|
||||
private static bool NotWhitespace(RenderTreeNode node)
|
||||
=> node.NodeType != RenderTreeNodeType.Text
|
||||
|| !string.IsNullOrWhiteSpace(node.TextContent);
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Blazor.Components;
|
||||
using Microsoft.Blazor.RenderTree;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BasicTestApp
|
||||
{
|
||||
public class KeyPressEventComponent : IComponent
|
||||
{
|
||||
private List<string> keysPressed = new List<string>();
|
||||
|
||||
public void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.AddText("Type here:");
|
||||
builder.OpenElement("input");
|
||||
builder.AddAttribute("onkeypress", OnKeyPressed);
|
||||
builder.CloseElement();
|
||||
|
||||
builder.OpenElement("ul");
|
||||
foreach (var key in keysPressed)
|
||||
{
|
||||
builder.OpenElement("li");
|
||||
builder.AddText(key);
|
||||
builder.CloseElement();
|
||||
}
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
private void OnKeyPressed(UIEventArgs eventInfo)
|
||||
{
|
||||
keysPressed.Add(((UIKeyboardEventArgs)eventInfo).Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
@using System.Collections.Generic
|
||||
@using Microsoft.Blazor.RenderTree
|
||||
Type here: <input onkeypress=@OnKeyPressed />
|
||||
<ul>
|
||||
@foreach (var key in keysPressed)
|
||||
{
|
||||
<li>@key</li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
@functions {
|
||||
List<string> keysPressed = new List<string>();
|
||||
|
||||
void OnKeyPressed(UIEventArgs eventArgs)
|
||||
{
|
||||
keysPressed.Add(((UIKeyboardEventArgs)eventArgs).Key);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue