Changing `@functions` block to `@code` block (#10591)

* Changing `@functions` block to `@code` block
This commit is contained in:
Artak 2019-05-29 13:36:24 -07:00 committed by GitHub
parent 443d60d8bb
commit 95d2f8ee7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
91 changed files with 133 additions and 133 deletions

View File

@ -40,7 +40,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<MyComponent bind-Value=""ParentValue"" /> <MyComponent bind-Value=""ParentValue"" />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -77,7 +77,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<MyComponent bind-Value=""ParentValue"" /> <MyComponent bind-Value=""ParentValue"" />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -114,7 +114,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<MyComponent bind-Value=""ParentValue"" bind-Value:event=""OnChanged"" /> <MyComponent bind-Value=""ParentValue"" bind-Value:event=""OnChanged"" />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -151,7 +151,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<MyComponent bind-Value=""ParentValue"" bind-Value:event=""OnChanged"" /> <MyComponent bind-Value=""ParentValue"" bind-Value:event=""OnChanged"" />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -184,7 +184,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<div bind=""@ParentValue"" /> <div bind=""@ParentValue"" />
@functions { @code {
public string ParentValue { get; set; } = ""hi""; public string ParentValue { get; set; } = ""hi"";
}"); }");
@ -217,7 +217,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<div bind-value=""@ParentValue"" /> <div bind-value=""@ParentValue"" />
@functions { @code {
public string ParentValue { get; set; } = ""hi""; public string ParentValue { get; set; } = ""hi"";
}"); }");
@ -252,7 +252,7 @@ namespace Test
// Act // Act
var result = CompileToCSharp(@" var result = CompileToCSharp(@"
<div bind-value=""@ParentValue"" /> <div bind-value=""@ParentValue"" />
@functions { @code {
public string ParentValue { get; set; } = ""hi""; public string ParentValue { get; set; } = ""hi"";
}"); }");
@ -272,7 +272,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input bind=""@ParentValue"" /> <input bind=""@ParentValue"" />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -293,7 +293,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input type=""text"" bind=""@CurrentDate"" bind:format=""MM/dd/yyyy""/> <input type=""text"" bind=""@CurrentDate"" bind:format=""MM/dd/yyyy""/>
@functions { @code {
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
}"); }");
@ -315,7 +315,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input type=""text"" bind=""@CurrentDate"" bind:format=""@Format""/> <input type=""text"" bind=""@CurrentDate"" bind:format=""@Format""/>
@functions { @code {
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
public string Format { get; set; } = ""MM/dd/yyyy""; public string Format { get; set; } = ""MM/dd/yyyy"";
@ -339,7 +339,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input type=""text"" bind=""@ParentValue"" /> <input type=""text"" bind=""@ParentValue"" />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -361,7 +361,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input type=""checkbox"" bind=""@Enabled"" /> <input type=""checkbox"" bind=""@Enabled"" />
@functions { @code {
public bool Enabled { get; set; } public bool Enabled { get; set; }
}"); }");
@ -382,7 +382,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input type=""text"" bind-value=""@ParentValue"" bind-value:event=""onchange"" /> <input type=""text"" bind-value=""@ParentValue"" bind-value:event=""onchange"" />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -404,7 +404,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input type=""text"" bind-value=""@CurrentDate"" bind-value:event=""onchange"" bind-value:format=""MM/dd"" /> <input type=""text"" bind-value=""@CurrentDate"" bind-value:event=""onchange"" bind-value:format=""MM/dd"" />
@functions { @code {
public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1);
}"); }");
@ -426,7 +426,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input type=""@(""text"")"" bind-value=""@ParentValue"" bind-value:event=""onchange"" visible /> <input type=""@(""text"")"" bind-value=""@ParentValue"" bind-value:event=""onchange"" visible />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -449,7 +449,7 @@ namespace Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<input bind-value=""@ParentValue"" bind-value:event=""onchange"" type=""text"" visible /> <input bind-value=""@ParentValue"" bind-value:event=""onchange"" type=""text"" visible />
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -477,7 +477,7 @@ namespace Test
<div bind-value=""@ParentValue"" bind-value:event=""onchange""> <div bind-value=""@ParentValue"" bind-value:event=""onchange"">
<span>@(42.ToString())</span> <span>@(42.ToString())</span>
</div> </div>
@functions { @code {
public int ParentValue { get; set; } = 42; public int ParentValue { get; set; } = 42;
}"); }");
@ -502,7 +502,7 @@ namespace Test
// Arrange & Act // Arrange & Act
var generated = CompileToCSharp(@" var generated = CompileToCSharp(@"
<input type=""text"" bind-first-second-third=""Text"" /> <input type=""text"" bind-first-second-third=""Text"" />
@functions { @code {
public string Text { get; set; } = ""text""; public string Text { get; set; } = ""text"";
}"); }");
@ -517,7 +517,7 @@ namespace Test
// Arrange & Act // Arrange & Act
var generated = CompileToCSharp(@" var generated = CompileToCSharp(@"
<input type=""text"" bind-first-=""Text"" /> <input type=""text"" bind-first-=""Text"" />
@functions { @code {
public string Text { get; set; } = ""text""; public string Text { get; set; } = ""text"";
}"); }");

View File

@ -216,7 +216,7 @@ namespace Test
var component = CompileToComponent($@" var component = CompileToComponent($@"
<MyComponent OnClick=""{expression}""/> <MyComponent OnClick=""{expression}""/>
@functions {{ @code {{
private int counter; private int counter;
private void Increment(UIMouseEventArgs e) {{ private void Increment(UIMouseEventArgs e) {{
counter++; counter++;
@ -261,7 +261,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<MyComponent OnClick=""@Increment""/> <MyComponent OnClick=""@Increment""/>
@functions { @code {
private int counter; private int counter;
private void Increment(UIEventArgs e) { private void Increment(UIEventArgs e) {
counter++; counter++;
@ -446,7 +446,7 @@ namespace Test
// Act // Act
var component = CompileToComponent(@" var component = CompileToComponent(@"
<p onmouseover=""@OnComponentHover"" style=""background: @ParentBgColor;"" /> <p onmouseover=""@OnComponentHover"" style=""background: @ParentBgColor;"" />
@functions { @code {
public string ParentBgColor { get; set; } = ""#FFFFFF""; public string ParentBgColor { get; set; } = ""#FFFFFF"";
public void OnComponentHover(UIMouseEventArgs e) public void OnComponentHover(UIMouseEventArgs e)

View File

@ -123,7 +123,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<GenericContext TItem=int Items=""@(new List<int>() { 1, 2, })"" ref=""_my"" /> <GenericContext TItem=int Items=""@(new List<int>() { 1, 2, })"" ref=""_my"" />
@functions { @code {
GenericContext<int> _my; GenericContext<int> _my;
void Foo() { GC.KeepAlive(_my); } void Foo() { GC.KeepAlive(_my); }
}"); }");
@ -190,7 +190,7 @@ namespace Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
<GenericContext Items=""@(new List<int>() { 1, 2, })"" ref=""_my"" /> <GenericContext Items=""@(new List<int>() { 1, 2, })"" ref=""_my"" />
@functions { @code {
GenericContext<int> _my; GenericContext<int> _my;
void Foo() { GC.KeepAlive(_my); } void Foo() { GC.KeepAlive(_my); }
}"); }");
@ -223,7 +223,7 @@ namespace Test
@typeparam TItem @typeparam TItem
<GenericContext Items=""@MyItems"" ref=""_my"" /> <GenericContext Items=""@MyItems"" ref=""_my"" />
@functions { @code {
[Parameter] List<TItem> MyItems { get; set; } [Parameter] List<TItem> MyItems { get; set; }
GenericContext<TItem> _my; GenericContext<TItem> _my;
void Foo() { GC.KeepAlive(_my); } void Foo() { GC.KeepAlive(_my); }

View File

@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
@foreach(var item in items) { @foreach(var item in items) {
@item @item
} }
@functions { @code {
string[] items = new[] { ""First"", ""Second"", ""Third"" }; string[] items = new[] { ""First"", ""Second"", ""Third"" };
} }
"); ");
@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Arrange/Act // Arrange/Act
var component = CompileToComponent( var component = CompileToComponent(
@"<elem attr=@MyHandleEvent /> @"<elem attr=@MyHandleEvent />
@functions { @code {
public bool HandlerWasCalled { get; set; } = false; public bool HandlerWasCalled { get; set; } = false;
void MyHandleEvent(Microsoft.AspNetCore.Components.UIEventArgs eventArgs) void MyHandleEvent(Microsoft.AspNetCore.Components.UIEventArgs eventArgs)
@ -341,7 +341,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Arrange/Act // Arrange/Act
var component = CompileToComponent( var component = CompileToComponent(
@"<input bind=""MyValue"" /> @"<input bind=""MyValue"" />
@functions { @code {
public string MyValue { get; set; } = ""Initial value""; public string MyValue { get; set; } = ""Initial value"";
}"); }");
var myValueProperty = component.GetType().GetProperty("MyValue"); var myValueProperty = component.GetType().GetProperty("MyValue");
@ -376,7 +376,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Arrange/Act // Arrange/Act
var component = CompileToComponent( var component = CompileToComponent(
@"<textarea bind=""MyValue"" ></textarea> @"<textarea bind=""MyValue"" ></textarea>
@functions { @code {
public string MyValue { get; set; } = ""Initial value""; public string MyValue { get; set; } = ""Initial value"";
}"); }");
var myValueProperty = component.GetType().GetProperty("MyValue"); var myValueProperty = component.GetType().GetProperty("MyValue");
@ -411,7 +411,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Arrange/Act // Arrange/Act
var component = CompileToComponent( var component = CompileToComponent(
@"<input bind=""MyDate"" /> @"<input bind=""MyDate"" />
@functions { @code {
public DateTime MyDate { get; set; } = new DateTime(2018, 3, 4, 1, 2, 3); public DateTime MyDate { get; set; } = new DateTime(2018, 3, 4, 1, 2, 3);
}"); }");
var myDateProperty = component.GetType().GetProperty("MyDate"); var myDateProperty = component.GetType().GetProperty("MyDate");
@ -449,7 +449,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
var testDateFormat = "ddd yyyy-MM-dd"; var testDateFormat = "ddd yyyy-MM-dd";
var component = CompileToComponent( var component = CompileToComponent(
$@"<input bind=""@MyDate"" bind:format=""{testDateFormat}"" /> $@"<input bind=""@MyDate"" bind:format=""{testDateFormat}"" />
@functions {{ @code {{
public DateTime MyDate {{ get; set; }} = new DateTime(2018, 3, 4); public DateTime MyDate {{ get; set; }} = new DateTime(2018, 3, 4);
}}"); }}");
var myDateProperty = component.GetType().GetProperty("MyDate"); var myDateProperty = component.GetType().GetProperty("MyDate");
@ -500,7 +500,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<button onclick=""@(x => Clicked = true)"" /> <button onclick=""@(x => Clicked = true)"" />
@functions { @code {
public bool Clicked { get; set; } public bool Clicked { get; set; }
}"); }");
@ -532,7 +532,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Arrange // Arrange
var component = CompileToComponent(@" var component = CompileToComponent(@"
<button onclick=""@OnClick"" /> <button onclick=""@OnClick"" />
@functions { @code {
public void OnClick(UIMouseEventArgs e) { Clicked = true; } public void OnClick(UIMouseEventArgs e) { Clicked = true; }
public bool Clicked { get; set; } public bool Clicked { get; set; }
}"); }");
@ -569,7 +569,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Arrange/Act // Arrange/Act
var component = CompileToComponent( var component = CompileToComponent(
@"<input bind=""MyValue"" /> @"<input bind=""MyValue"" />
@functions { @code {
public bool MyValue { get; set; } = true; public bool MyValue { get; set; } = true;
}"); }");
var myValueProperty = component.GetType().GetProperty("MyValue"); var myValueProperty = component.GetType().GetProperty("MyValue");
@ -605,7 +605,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
var myEnumType = FullTypeName<MyEnum>(); var myEnumType = FullTypeName<MyEnum>();
var component = CompileToComponent( var component = CompileToComponent(
$@"<input bind=""MyValue"" /> $@"<input bind=""MyValue"" />
@functions {{ @code {{
public {myEnumType} MyValue {{ get; set; }} = {myEnumType}.{nameof(MyEnum.FirstValue)}; public {myEnumType} MyValue {{ get; set; }} = {myEnumType}.{nameof(MyEnum.FirstValue)};
}}"); }}");
var myValueProperty = component.GetType().GetProperty("MyValue"); var myValueProperty = component.GetType().GetProperty("MyValue");
@ -695,7 +695,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
@(Repeat(@<div>@(""Hello, World!"".ToLower())</div>, 3)) @(Repeat(@<div>@(""Hello, World!"".ToLower())</div>, 3))
@functions { @code {
RenderFragment Repeat(RenderFragment template, int count) RenderFragment Repeat(RenderFragment template, int count)
{ {
return (b) => return (b) =>
@ -733,7 +733,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
var component = CompileToComponent(@" var component = CompileToComponent(@"
@(Repeat((context) => @<div>@context.ToLower()</div>, ""Hello, World!"", 3)) @(Repeat((context) => @<div>@context.ToLower()</div>, ""Hello, World!"", 3))
@functions { @code {
RenderFragment Repeat<T>(RenderFragment<T> template, T value, int count) RenderFragment Repeat<T>(RenderFragment<T> template, T value, int count)
{ {
return (b) => return (b) =>

View File

@ -6,7 +6,7 @@
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button> <button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
@functions { @code {
int currentCount = 0; int currentCount = 0;
void IncrementCount() void IncrementCount()

View File

@ -35,7 +35,7 @@ else
</table> </table>
} }
@functions { @code {
WeatherForecast[] forecasts; WeatherForecast[] forecasts;
protected override async Task OnInitAsync() protected override async Task OnInitAsync()

View File

@ -25,7 +25,7 @@
</ul> </ul>
</div> </div>
@functions { @code {
bool collapseNavMenu = true; bool collapseNavMenu = true;
string NavMenuCssClass => collapseNavMenu ? "collapse" : null; string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

View File

@ -9,7 +9,7 @@
and tell us what you think. and tell us what you think.
</div> </div>
@functions { @code {
// Demonstrates how a parent component can supply parameters // Demonstrates how a parent component can supply parameters
[Parameter] string Title { get; set; } [Parameter] string Title { get; set; }
} }

View File

@ -6,7 +6,7 @@
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button> <button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
@functions { @code {
int currentCount = 0; int currentCount = 0;
void IncrementCount() void IncrementCount()

View File

@ -34,7 +34,7 @@ else
</table> </table>
} }
@functions { @code {
WeatherForecast[] forecasts; WeatherForecast[] forecasts;
protected override async Task OnInitAsync() protected override async Task OnInitAsync()

View File

@ -25,7 +25,7 @@
</ul> </ul>
</div> </div>
@functions { @code {
bool collapseNavMenu = true; bool collapseNavMenu = true;
string NavMenuCssClass => collapseNavMenu ? "collapse" : null; string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

View File

@ -9,7 +9,7 @@
and tell us what you think. and tell us what you think.
</div> </div>
@functions { @code {
// Demonstrates how a parent component can supply parameters // Demonstrates how a parent component can supply parameters
[Parameter] string Title { get; set; } [Parameter] string Title { get; set; }
} }

View File

@ -3,7 +3,7 @@
Hello, world! Hello, world!
@functions { @code {
protected override void OnAfterRender() protected override void OnAfterRender()
{ {
BenchmarkEvent.Send(JSRuntime, "Rendered index.cshtml"); BenchmarkEvent.Send(JSRuntime, "Rendered index.cshtml");

View File

@ -22,7 +22,7 @@
<p>Deserialized <strong id="deserialized-count">@numPeopleDeserialized</strong> people</p> <p>Deserialized <strong id="deserialized-count">@numPeopleDeserialized</strong> people</p>
} }
@functions { @code {
static string[] Clearances = new[] { "Alpha", "Beta", "Gamma", "Delta", "Epsilon" }; static string[] Clearances = new[] { "Alpha", "Beta", "Gamma", "Delta", "Epsilon" };
Person smallOrgChart = GenerateOrgChart(1, 4); Person smallOrgChart = GenerateOrgChart(1, 4);
Person largeOrgChart = GenerateOrgChart(5, 4); Person largeOrgChart = GenerateOrgChart(5, 4);

View File

@ -32,7 +32,7 @@ Number of items: <input id="num-items" type="number" bind=@numItems />
</table> </table>
} }
@functions { @code {
int numItems = 10; int numItems = 10;
bool show = false; bool show = false;

View File

@ -6,7 +6,7 @@
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button> <button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
@functions { @code {
int currentCount = 0; int currentCount = 0;
void IncrementCount() void IncrementCount()

View File

@ -43,7 +43,7 @@ else
</p> </p>
} }
@functions { @code {
[Parameter] DateTime StartDate { get; set; } [Parameter] DateTime StartDate { get; set; }
WeatherForecast[] forecasts; WeatherForecast[] forecasts;

View File

@ -25,7 +25,7 @@
</ul> </ul>
</div> </div>
@functions { @code {
bool collapseNavMenu = true; bool collapseNavMenu = true;
void ToggleNavMenu() void ToggleNavMenu()

View File

@ -4,7 +4,7 @@
<CascadingValue T="Task<AuthenticationState>" Value="@_currentAuthenticationStateTask" ChildContent="@ChildContent" /> <CascadingValue T="Task<AuthenticationState>" Value="@_currentAuthenticationStateTask" ChildContent="@ChildContent" />
@functions { @code {
private Task<AuthenticationState> _currentAuthenticationStateTask; private Task<AuthenticationState> _currentAuthenticationStateTask;
/// <summary> /// <summary>

View File

@ -8,7 +8,7 @@ Child components follow.
<p><MessageComponent Message=@message /></p> <p><MessageComponent Message=@message /></p>
} }
@functions { @code {
int numAdded = 0; int numAdded = 0;
List<string> currentChildrenMessages = new List<string>(); List<string> currentChildrenMessages = new List<string>();

View File

@ -3,7 +3,7 @@
<input ref="myInput" value="Value set during render" /> <input ref="myInput" value="Value set during render" />
@functions { @code {
ElementRef myInput; ElementRef myInput;
protected override void OnAfterRender() protected override void OnAfterRender()

View File

@ -6,7 +6,7 @@
<button id="tock" onclick="@Tock">Tock</button> <button id="tock" onclick="@Tock">Tock</button>
</div> </div>
@functions @code
{ {
TaskCompletionSource<object> _tcs; TaskCompletionSource<object> _tcs;
string state = "Stopped"; string state = "Stopped";

View File

@ -22,7 +22,7 @@
<hr /> <hr />
<Links /> <Links />
@functions { @code {
protected override void OnInit() protected override void OnInit()
{ {
// Start at AuthHome, not at any other component in the same app that happens to // Start at AuthHome, not at any other component in the same app that happens to

View File

@ -32,7 +32,7 @@ else
</p> </p>
} }
@functions @code
{ {
static Predicate<Claim> TestClaimPredicate = c => c.Type == "test-claim"; static Predicate<Claim> TestClaimPredicate = c => c.Type == "test-claim";

View File

@ -137,7 +137,7 @@
<button id="select-box-add-option" onclick="@AddAndSelectNewSelectOption">Add and select new item</button> <button id="select-box-add-option" onclick="@AddAndSelectNewSelectOption">Add and select new item</button>
</p> </p>
@functions { @code {
string textboxInitiallyBlankValue = null; string textboxInitiallyBlankValue = null;
string textboxInitiallyPopulatedValue = "Hello"; string textboxInitiallyPopulatedValue = "Hello";

View File

@ -10,7 +10,7 @@
Flag 2: <strong id="flag-2">@MyFlag2</strong> Flag 2: <strong id="flag-2">@MyFlag2</strong>
</p> </p>
@functions { @code {
[CascadingParameter(Name = "TestFlag1")] bool MyFlag1 { get; set; } [CascadingParameter(Name = "TestFlag1")] bool MyFlag1 { get; set; }
[CascadingParameter(Name = "TestFlag2")] bool MyFlag2 { get; set; } [CascadingParameter(Name = "TestFlag2")] bool MyFlag2 { get; set; }
} }

View File

@ -3,6 +3,6 @@
<strong id="current-count">@CurrentCounter.NumClicks</strong> <strong id="current-count">@CurrentCounter.NumClicks</strong>
</p> </p>
@functions { @code {
[CascadingParameter] CounterDTO CurrentCounter { get; set; } [CascadingParameter] CounterDTO CurrentCounter { get; set; }
} }

View File

@ -16,7 +16,7 @@
<button id="decrement-count" onclick=@Ancestor.DecrementCount>Decrement</button> <button id="decrement-count" onclick=@Ancestor.DecrementCount>Decrement</button>
</p> </p>
@functions { @code {
int numRenders = 0; int numRenders = 0;
[CascadingParameter] ICanDecrement Ancestor { get; set; } [CascadingParameter] ICanDecrement Ancestor { get; set; }

View File

@ -20,7 +20,7 @@
<p><label><input type="checkbox" id="toggle-flag-1" bind=currentFlagValue1 /> Flag 1</label></p> <p><label><input type="checkbox" id="toggle-flag-1" bind=currentFlagValue1 /> Flag 1</label></p>
<p><label><input type="checkbox" id="toggle-flag-2" bind=currentFlagValue2 /> Flag 2</label></p> <p><label><input type="checkbox" id="toggle-flag-2" bind=currentFlagValue2 /> Flag 2</label></p>
@functions { @code {
CounterDTO counterState = new CounterDTO { NumClicks = 100 }; CounterDTO counterState = new CounterDTO { NumClicks = 100 };
bool currentFlagValue1; bool currentFlagValue1;
bool currentFlagValue2; bool currentFlagValue2;

View File

@ -24,7 +24,7 @@
</label> </label>
</fieldset> </fieldset>
@functions { @code {
bool _toggleCapturedComponentPresence = true; bool _toggleCapturedComponentPresence = true;
CounterComponent _myChildCounter; CounterComponent _myChildCounter;

View File

@ -1,5 +1,5 @@
<span>@(isAfterDelay ? "😊" :"WAITING")</span> <span>@(isAfterDelay ? "😊" :"WAITING")</span>
@functions @code
{ {
protected bool isAfterDelay; protected bool isAfterDelay;

View File

@ -12,7 +12,7 @@
<p id="listening-message">Listening</p> <p id="listening-message">Listening</p>
} }
@functions { @code {
int currentCount = 0; int currentCount = 0;
bool handleClicks = true; bool handleClicks = true;

View File

@ -5,7 +5,7 @@
<button onclick="@IncrementCount">Click me</button> <button onclick="@IncrementCount">Click me</button>
@functions { @code {
int currentCount = 0; int currentCount = 0;
void IncrementCount() void IncrementCount()

View File

@ -1,5 +1,5 @@
<div id="cool_beans" data-tab="@TabId">@TabId</div> <div id="cool_beans" data-tab="@TabId">@TabId</div>
@functions { @code {
string TabId = "17"; string TabId = "17";
} }

View File

@ -15,7 +15,7 @@
<button id="run-with-double-dispatch" onclick=@RunWithDoubleDispatch>Run with double dispatch</button> <button id="run-with-double-dispatch" onclick=@RunWithDoubleDispatch>Run with double dispatch</button>
<button id="run-async-with-dispatch" onclick=@RunAsyncWorkWithDispatch>Run async work with dispatch</button> <button id="run-async-with-dispatch" onclick=@RunAsyncWorkWithDispatch>Run async work with dispatch</button>
@functions { @code {
string result; string result;
async Task RunWithoutDispatch() async Task RunWithoutDispatch()

View File

@ -25,7 +25,7 @@
Toggle input Toggle input
</label> </label>
@functions { @code {
int _count = 0; int _count = 0;
bool _toggleCapturedElementPresence = true; bool _toggleCapturedElementPresence = true;
ElementRef _myInput; ElementRef _myInput;

View File

@ -24,7 +24,7 @@
<textarea readonly bind="@logValue"></textarea> <textarea readonly bind="@logValue"></textarea>
@functions { @code {
string logValue = string.Empty; string logValue = string.Empty;
void LogEvent(string message) void LogEvent(string message)

View File

@ -1,7 +1,7 @@
<button onclick="@OnClick">@Text</button> <button onclick="@OnClick">@Text</button>
@functions { @code {
[Parameter] int Count { get; set; } [Parameter] int Count { get; set; }
[Parameter] EventCallback<int> CountChanged { get; set; } [Parameter] EventCallback<int> CountChanged { get; set; }
[Parameter] string Text { get; set; } [Parameter] string Text { get; set; }

View File

@ -35,7 +35,7 @@
<ButtonComponent bind-Count="buttonComponentCount" Text="Unbound Lambda Bind-To-Component" /> <ButtonComponent bind-Count="buttonComponentCount" Text="Unbound Lambda Bind-To-Component" />
</div> </div>
@functions { @code {
int renderCount; int renderCount;
int buttonComponentCount = 1; // Avoid CS0649 int buttonComponentCount = 1; // Avoid CS0649

View File

@ -1,7 +1,7 @@
<button onclick="@OnClick">@Text</button> <button onclick="@OnClick">@Text</button>
@functions { @code {
[Parameter] EventCallback OnClick { get; set; } [Parameter] EventCallback OnClick { get; set; }
[Parameter] string Text { get; set; } [Parameter] string Text { get; set; }
} }

View File

@ -1,7 +1,7 @@
<InnerButton OnClick="@OnClick" Text="@Text"/> <InnerButton OnClick="@OnClick" Text="@Text"/>
@functions { @code {
[Parameter] EventCallback OnClick { get; set; } [Parameter] EventCallback OnClick { get; set; }
[Parameter] string Text { get; set; } [Parameter] string Text { get; set; }
} }

View File

@ -1,7 +1,7 @@
<button onclick="@OnClick">@Text</button> <button onclick="@OnClick">@Text</button>
@functions { @code {
[Parameter] EventCallback<UIMouseEventArgs> OnClick { get; set; } [Parameter] EventCallback<UIMouseEventArgs> OnClick { get; set; }
[Parameter] string Text { get; set; } [Parameter] string Text { get; set; }
} }

View File

@ -3,6 +3,6 @@
@ChildContent @ChildContent
</div> </div>
@functions { @code {
[Parameter] RenderFragment ChildContent { get; set; } [Parameter] RenderFragment ChildContent { get; set; }
} }

View File

@ -28,7 +28,7 @@
<p id="event-handled">Event was handled</p> <p id="event-handled">Event was handled</p>
} }
@functions { @code {
bool didHandleEvent; bool didHandleEvent;
async Task HandleClick() async Task HandleClick()

View File

@ -29,7 +29,7 @@
<ComponentFromPackage /> <ComponentFromPackage />
@functions @code
{ {
string result; string result;

View File

@ -16,7 +16,7 @@
Another input (to distract you) <input id="other" /> Another input (to distract you) <input id="other" />
</p> </p>
@functions { @code {
string message; string message;
@ -48,4 +48,4 @@
{ {
message = string.Empty; message = string.Empty;
} }
} }

View File

@ -12,7 +12,7 @@
</p> </p>
<p> <p>
This example also shows that you don't strictly have to use EditForm. You can manually This example also shows that you don't strictly have to use EditForm. You can manually
cascade an EditContext to the components that integrate with it. cascade an EditContext to the components that integrate with it.
</p> </p>
<form onsubmit="@HandleSubmit"> <form onsubmit="@HandleSubmit">
@ -34,7 +34,7 @@
<div id="submission-status">@submissionStatus</div> <div id="submission-status">@submissionStatus</div>
@functions { @code {
MyModel person = new MyModel(); MyModel person = new MyModel();
EditContext editContext; EditContext editContext;
string submissionStatus; string submissionStatus;

View File

@ -28,7 +28,7 @@
<span id="last-callback">@lastCallback</span> <span id="last-callback">@lastCallback</span>
} }
@functions { @code {
string lastCallback; string lastCallback;
[Required(ErrorMessage = "Please choose a username")] [Required(ErrorMessage = "Please choose a username")]

View File

@ -50,7 +50,7 @@
<ul>@foreach (var entry in submissionLog) { <li>@entry</li> }</ul> <ul>@foreach (var entry in submissionLog) { <li>@entry</li> }</ul>
@functions { @code {
Person person = new Person(); Person person = new Person();
// Usually this would be in a different file // Usually this would be in a different file

View File

@ -20,7 +20,7 @@
<span id="test-outcome">@testOutcome</span> <span id="test-outcome">@testOutcome</span>
@functions { @code {
string uri = ""; string uri = "";
HttpStatusCode? responseStatusCode; HttpStatusCode? responseStatusCode;
string responseStatusText; string responseStatusText;

View File

@ -11,7 +11,7 @@
<p id="response-text">@responseText</p> <p id="response-text">@responseText</p>
} }
@functions @code
{ {
bool requestInProgress = false; bool requestInProgress = false;
string testServerBaseUrl; string testServerBaseUrl;

View File

@ -60,7 +60,7 @@
} }
</style> </style>
@functions { @code {
string uri = "http://api.icndb.com/jokes/random"; string uri = "http://api.icndb.com/jokes/random";
string method = "GET"; string method = "GET";
string requestBody = ""; string requestBody = "";

View File

@ -70,7 +70,7 @@
@((RenderFragment)RenderSelectedComponent) @((RenderFragment)RenderSelectedComponent)
</app> </app>
@functions { @code {
string SelectedComponentTypeName { get; set; } = "none"; string SelectedComponentTypeName { get; set; } = "none";
Type SelectedComponentType Type SelectedComponentType

View File

@ -4,6 +4,6 @@
<p id="test-result">@inputText</p> <p id="test-result">@inputText</p>
@functions { @code {
string inputText { get; set; } string inputText { get; set; }
} }

View File

@ -51,7 +51,7 @@
<p id="done-with-interop">Done with interop.</p> <p id="done-with-interop">Done with interop.</p>
} }
@functions { @code {
public IDictionary<string, string> ReturnValues { get; set; } = new Dictionary<string, string>(); public IDictionary<string, string> ReturnValues { get; set; } = new Dictionary<string, string>();
public IDictionary<string, string> Invocations { get; set; } = new Dictionary<string, string>(); public IDictionary<string, string> Invocations { get; set; } = new Dictionary<string, string>();

View File

@ -22,7 +22,7 @@
<input id="val-set-by-interop" ref="@myElem" /> <input id="val-set-by-interop" ref="@myElem" />
</p> </p>
@functions { @code {
string infoFromJs; string infoFromJs;
ElementRef myElem; ElementRef myElem;

View File

@ -25,7 +25,7 @@
.key-cases .node .node .children { margin-left: 1.1rem; } .key-cases .node .node .children { margin-left: 1.1rem; }
</style> </style>
@functions { @code {
string modelJson = @"{ string modelJson = @"{
""label"": ""root"", ""label"": ""root"",
""children"": [ ""children"": [

View File

@ -32,7 +32,7 @@
} }
</div> </div>
@functions { @code {
public class Node public class Node
{ {
public object Key { get; set; } public object Key { get; set; }

View File

@ -8,7 +8,7 @@ Type here: <input onkeypress=@OnKeyPressed />
} }
</ul> </ul>
@functions { @code {
List<string> keysPressed = new List<string>(); List<string> keysPressed = new List<string>();
void OnKeyPressed(UIKeyboardEventArgs eventArgs) void OnKeyPressed(UIKeyboardEventArgs eventArgs)

View File

@ -24,7 +24,7 @@
@((MarkupString)myMarkup) @((MarkupString)myMarkup)
@functions { @code {
bool changeOutput; bool changeOutput;
string myMarkup = "<p class='markup-string-value'>This is a <em>markup string</em>.</p>"; string myMarkup = "<p class='markup-string-value'>This is a <em>markup string</em>.</p>";

View File

@ -1,4 +1,4 @@
<span style="color: red" class="message">@Message</span> <span style="color: red" class="message">@Message</span>
@functions { @code {
[Parameter] string Message { get; set; } [Parameter] string Message { get; set; }
} }

View File

@ -24,7 +24,7 @@
</p> </p>
</div> </div>
@functions { @code {
string message; string message;
@ -72,4 +72,4 @@
{ {
message = string.Empty; message = string.Empty;
} }
} }

View File

@ -13,7 +13,7 @@
Toggle: <input type="checkbox" bind="ShowFooter" id="toggle"/> Toggle: <input type="checkbox" bind="ShowFooter" id="toggle"/>
@functions { @code {
List<Item> Items { get; } = new List<Item>() List<Item> Items { get; } = new List<Item>()
{ {
new Item(){ Col1 = "a0", Col2 = "b0", Col3 = "c0", }, new Item(){ Col1 = "a0", Col2 = "b0", Col3 = "c0", },
@ -29,4 +29,4 @@ Toggle: <input type="checkbox" bind="ShowFooter" id="toggle"/>
public string Col2 { get; set; } public string Col2 { get; set; }
public string Col3 { get; set; } public string Col3 { get; set; }
} }
} }

View File

@ -10,7 +10,7 @@
} }
</ol> </ol>
@functions{ @code{
[Parameter] IEnumerable<TItem> Items { get; set; } [Parameter] IEnumerable<TItem> Items { get; set; }
[Parameter] RenderFragment<Context> Template { get; set; } [Parameter] RenderFragment<Context> Template { get; set; }
@ -21,4 +21,4 @@
public TItem Item { get; set; } public TItem Item { get; set; }
} }
} }

View File

@ -1,5 +1,5 @@
@ChildContent @ChildContent
@functions { @code {
// Note: The lack of any whitespace or other output besides @ChildContent is important for // Note: The lack of any whitespace or other output besides @ChildContent is important for
// what scenarios this component is used for in E2E tests. // what scenarios this component is used for in E2E tests.

View File

@ -15,7 +15,7 @@
<button id="increment-count" onclick="@(() => count++)">Click me</button> <button id="increment-count" onclick="@(() => count++)">Click me</button>
</p> </p>
@functions { @code {
int count; int count;
bool firstRender = false; bool firstRender = false;
protected override Task OnAfterRenderAsync() protected override Task OnAfterRenderAsync()

View File

@ -1,7 +1,7 @@
<div class="supplied">You supplied: @SuppliedValue</div> <div class="supplied">You supplied: @SuppliedValue</div>
<div class="computed">I computed: @computedValue</div> <div class="computed">I computed: @computedValue</div>
@functions { @code {
[Parameter] [Parameter]
int SuppliedValue { get; set; } int SuppliedValue { get; set; }

View File

@ -1,6 +1,6 @@
<PropertiesChangedHandlerChild SuppliedValue=@valueToSupply /> <PropertiesChangedHandlerChild SuppliedValue=@valueToSupply />
<button onclick=@(x => valueToSupply++)>Increment</button> <button onclick=@(x => valueToSupply++)>Increment</button>
@functions { @code {
private int valueToSupply = 100; private int valueToSupply = 100;
} }

View File

@ -10,7 +10,7 @@
<p>The end</p> <p>The end</p>
</div> </div>
@functions { @code {
bool showFragment; bool showFragment;
static RenderFragment ExampleFragment = builder => static RenderFragment ExampleFragment = builder =>

View File

@ -30,7 +30,7 @@
} }
</ul> </ul>
@functions { @code {
Random rng = new Random(); Random rng = new Random();
TodoItem[] todoItems = new[] TodoItem[] todoItems = new[]
{ {

View File

@ -5,7 +5,7 @@
<span id="test-info">@UrlLocation</span> <span id="test-info">@UrlLocation</span>
@functions{ @code{
string UrlLocation; string UrlLocation;
protected override void OnInit() protected override void OnInit()

View File

@ -1,7 +1,7 @@
@page "/WithNumberParameters/{TestInt:int}/{TestLong:long}/{TestDouble:double}/{TestFloat:float}/{TestDec:decimal}" @page "/WithNumberParameters/{TestInt:int}/{TestLong:long}/{TestDouble:double}/{TestFloat:float}/{TestDec:decimal}"
<div id="test-info">Test parameters: @TestInt @TestLong @TestDouble @TestFloat @TestDec</div> <div id="test-info">Test parameters: @TestInt @TestLong @TestDouble @TestFloat @TestDec</div>
@functions @code
{ {
[Parameter] int TestInt { get; set; } [Parameter] int TestInt { get; set; }
[Parameter] long TestLong { get; set; } [Parameter] long TestLong { get; set; }

View File

@ -3,7 +3,7 @@
<div id="test-info">Your full name is @FirstName @LastName.</div> <div id="test-info">Your full name is @FirstName @LastName.</div>
<Links /> <Links />
@functions @code
{ {
[Parameter] string FirstName { get; set; } [Parameter] string FirstName { get; set; }

View File

@ -4,6 +4,6 @@
<button onclick=@(() => { radius *= 2; })>Click me</button> <button onclick=@(() => { radius *= 2; })>Click me</button>
@functions { @code {
int radius = 10; int radius = 10;
} }

Before

Width:  |  Height:  |  Size: 220 B

After

Width:  |  Height:  |  Size: 215 B

View File

@ -20,7 +20,7 @@
} }
</table> </table>
@functions { @code {
[Parameter] [Parameter]
RenderFragment Header { get; set; } RenderFragment Header { get; set; }
@ -32,4 +32,4 @@
[Parameter] [Parameter]
IReadOnlyList<TItem> Items { get; set; } IReadOnlyList<TItem> Items { get; set; }
} }

View File

@ -21,7 +21,7 @@
</p> </p>
</div> </div>
@functions { @code {
string message; string message;
@ -36,4 +36,4 @@
{ {
message = string.Empty; message = string.Empty;
} }
} }

View File

@ -7,6 +7,6 @@
<Router AppAssembly=typeof(ComponentsApp.App.App).Assembly /> <Router AppAssembly=typeof(ComponentsApp.App.App).Assembly />
</CascadingValue> </CascadingValue>
@functions{ @code{
[Parameter] public string Name { get; set; } [Parameter] public string Name { get; set; }
} }

View File

@ -6,7 +6,7 @@
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button> <button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
@functions { @code {
int currentCount = 0; int currentCount = 0;
void IncrementCount() void IncrementCount()

View File

@ -3,13 +3,13 @@
<h1>Error</h1> <h1>Error</h1>
@if(ShouldCauseError) @if(ShouldCauseError)
{ {
throw new InvalidOperationException("Exception while rendering"); throw new InvalidOperationException("Exception while rendering");
} }
else else
{ {
<button id="cause-error" onclick="@CauseError">Cause error</button> <button id="cause-error" onclick="@CauseError">Cause error</button>
} }
@functions { @code {
public bool ShouldCauseError { get; set; } public bool ShouldCauseError { get; set; }
void CauseError() void CauseError()

View File

@ -43,7 +43,7 @@ else
</p> </p>
} }
@functions { @code {
[Parameter] DateTime StartDate { get; set; } [Parameter] DateTime StartDate { get; set; }
WeatherForecast[] forecasts; WeatherForecast[] forecasts;

View File

@ -3,6 +3,6 @@
<h1>Greeter</h1> <h1>Greeter</h1>
<p class="greeting">Hello @Name</p> <p class="greeting">Hello @Name</p>
@functions { @code {
[CascadingParameter(Name=nameof(Name))] public string Name { get; set; } [CascadingParameter(Name=nameof(Name))] public string Name { get; set; }
} }

View File

@ -5,7 +5,7 @@
<h1>Ticker</h1> <h1>Ticker</h1>
<p class="tick-value">@tick</p> <p class="tick-value">@tick</p>
@functions { @code {
int tick; int tick;
private bool _isDisposed; private bool _isDisposed;

View File

@ -45,7 +45,7 @@
</ul> </ul>
</div> </div>
@functions { @code {
bool collapseNavMenu = true; bool collapseNavMenu = true;
void ToggleNavMenu() void ToggleNavMenu()

View File

@ -4,7 +4,7 @@
<button onclick="@ChangeLabel">@buttonLabel </button> <button onclick="@ChangeLabel">@buttonLabel </button>
</div> </div>
@functions { @code {
string buttonLabel = "Click me"; string buttonLabel = "Click me";
void ChangeLabel() void ChangeLabel()

View File

@ -35,7 +35,7 @@ else
</table> </table>
} }
@functions { @code {
[Parameter] DateTime StartDate { get; set; } [Parameter] DateTime StartDate { get; set; }
WeatherForecast[] forecasts; WeatherForecast[] forecasts;

View File

@ -1,7 +1,7 @@
@page "/components/throws" @page "/components/throws"
@* This is expected to throw and result in a 500 *@ @* This is expected to throw and result in a 500 *@
@functions { @code {
protected override async Task OnInitAsync() protected override async Task OnInitAsync()
{ {
await base.OnInitAsync(); await base.OnInitAsync();

View File

@ -1,5 +1,5 @@
<h3>Component1</h3> <h3>Component1</h3>
@functions { @code {
} }

View File

@ -6,7 +6,7 @@
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button> <button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
@functions { @code {
int currentCount = 0; int currentCount = 0;
void IncrementCount() void IncrementCount()

View File

@ -35,7 +35,7 @@ else
</table> </table>
} }
@functions { @code {
WeatherForecast[] forecasts; WeatherForecast[] forecasts;
protected override async Task OnInitAsync() protected override async Task OnInitAsync()

View File

@ -31,7 +31,7 @@
</NotAuthorized> </NotAuthorized>
</AuthorizeView> </AuthorizeView>
@functions { @code {
bool canEditProfile; bool canEditProfile;
protected override void OnInit() protected override void OnInit()

View File

@ -25,7 +25,7 @@
</ul> </ul>
</div> </div>
@functions { @code {
bool collapseNavMenu = true; bool collapseNavMenu = true;
string NavMenuCssClass => collapseNavMenu ? "collapse" : null; string NavMenuCssClass => collapseNavMenu ? "collapse" : null;