Skip to content

Commit 4120007

Browse files
authored
Support for Blazor webassembly (#360)
* added linker config to make library work on mono project + added a webassembly blazor app whith some dynamic order by * correct codefactor issue correct codefactor issue
1 parent 9d5c560 commit 4120007

26 files changed

+1291
-0
lines changed

System.Linq.Dynamic.Core.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_netcore2.1_Cosmo
7777
EndProject
7878
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp_net452_CosmosDb", "src-console\ConsoleApp_net452_CosmosDb\ConsoleApp_net452_CosmosDb.csproj", "{0034821E-740D-4553-821B-14CE9213C43C}"
7979
EndProject
80+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src-blazor", "src-blazor", "{122BC4FA-7563-4E35-9D17-077F16F1629F}"
81+
EndProject
82+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAppTest", "src-blazor\BlazorAppTest\BlazorAppTest.csproj", "{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}"
83+
EndProject
8084
Global
8185
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8286
Debug|Any CPU = Debug|Any CPU
@@ -475,6 +479,22 @@ Global
475479
{0034821E-740D-4553-821B-14CE9213C43C}.Release|x64.Build.0 = Release|Any CPU
476480
{0034821E-740D-4553-821B-14CE9213C43C}.Release|x86.ActiveCfg = Release|Any CPU
477481
{0034821E-740D-4553-821B-14CE9213C43C}.Release|x86.Build.0 = Release|Any CPU
482+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
483+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
484+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Debug|ARM.ActiveCfg = Debug|Any CPU
485+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Debug|ARM.Build.0 = Debug|Any CPU
486+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Debug|x64.ActiveCfg = Debug|Any CPU
487+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Debug|x64.Build.0 = Debug|Any CPU
488+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Debug|x86.ActiveCfg = Debug|Any CPU
489+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Debug|x86.Build.0 = Debug|Any CPU
490+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
491+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Release|Any CPU.Build.0 = Release|Any CPU
492+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Release|ARM.ActiveCfg = Release|Any CPU
493+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Release|ARM.Build.0 = Release|Any CPU
494+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Release|x64.ActiveCfg = Release|Any CPU
495+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Release|x64.Build.0 = Release|Any CPU
496+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Release|x86.ActiveCfg = Release|Any CPU
497+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8}.Release|x86.Build.0 = Release|Any CPU
478498
EndGlobalSection
479499
GlobalSection(SolutionProperties) = preSolution
480500
HideSolutionNode = FALSE
@@ -504,6 +524,7 @@ Global
504524
{6D21EBF2-C92D-4AE0-9BC3-47C63928F88A} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
505525
{D160E2CF-A7E1-4DDE-9AB8-8CFB0087DCEB} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
506526
{0034821E-740D-4553-821B-14CE9213C43C} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
527+
{CD80A3AC-B0E1-45ED-BE07-DE6A0F1D4CD8} = {122BC4FA-7563-4E35-9D17-077F16F1629F}
507528
EndGlobalSection
508529
GlobalSection(ExtensibilityGlobals) = postSolution
509530
SolutionGuid = {94C56722-194E-4B8B-BC23-B3F754E89A20}

src-blazor/BlazorAppTest/App.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
6+
</PropertyGroup>
7+
8+
<PropertyGroup>
9+
<BlazorWebAssemblyEnableLinking>true</BlazorWebAssemblyEnableLinking>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview2.20160.5" />
14+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview2.20160.5" PrivateAssets="all" />
15+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview2.20160.5" PrivateAssets="all" />
16+
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview2.20160.5" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.csproj" />
21+
</ItemGroup>
22+
</Project>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
@page "/"
2+
@inject HttpClient Http
3+
@using System.Linq.Dynamic.Core
4+
<h1>Weather forecast</h1>
5+
6+
<p>This component demonstrates fetching data from the server.</p>
7+
8+
@if (forecasts == null)
9+
{
10+
<p><em>Loading...</em></p>
11+
}
12+
else
13+
{
14+
<div class="d-flex">
15+
<h3>Order by</h3>
16+
<div class="form-inline ml-4">
17+
<div class="form-check form-check-inline">
18+
<input class="form-check-input" type="checkbox" name="rbOrder" id="cbOrder" checked="@isDescending" @onclick="@SetOrderingDirection">
19+
<label class="form-check-label" for="cbOrder">descending</label>
20+
</div>
21+
</div>
22+
</div>
23+
<div class="form-inline">
24+
@foreach (var member in typeof(WeatherForecast).GetProperties().Select(p => p.Name))
25+
{
26+
<div class="form-check form-check-inline">
27+
<input class="form-check-input" type="radio" name="rbOrder" id="@("rbOrder" + member)" checked="@(currentOrder == member)" @onchange="@((args) => SetOrder(member))">
28+
<label class="form-check-label" for="@("rbOrder" + member)">@member</label>
29+
</div>
30+
}
31+
</div>
32+
<table class="table">
33+
<thead>
34+
<tr>
35+
<th>Date</th>
36+
<th>Temp. (C)</th>
37+
<th>Temp. (F)</th>
38+
<th>Summary</th>
39+
</tr>
40+
</thead>
41+
<tbody>
42+
@foreach (var forecast in forecasts)
43+
{
44+
<tr>
45+
<td>@forecast.Date.ToShortDateString()</td>
46+
<td>@forecast.TemperatureC</td>
47+
<td>@forecast.TemperatureF</td>
48+
<td>@forecast.Summary</td>
49+
</tr>
50+
}
51+
</tbody>
52+
</table>
53+
}
54+
55+
@code {
56+
private WeatherForecast[] forecasts;
57+
private string currentOrder;
58+
private bool isDescending;
59+
60+
protected override async Task OnInitializedAsync()
61+
{
62+
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
63+
}
64+
65+
protected void SetOrder(string propertyName)
66+
{
67+
currentOrder = propertyName;
68+
Order();
69+
}
70+
71+
protected void SetOrderingDirection()
72+
{
73+
isDescending = !isDescending;
74+
Order();
75+
}
76+
77+
private void Order()
78+
{
79+
if (!string.IsNullOrEmpty(currentOrder))
80+
{
81+
forecasts = forecasts.AsQueryable().OrderBy($"{currentOrder} {(isDescending ? "descending" : "ascending")}").ToArray();
82+
}
83+
84+
}
85+
86+
87+
public class WeatherForecast
88+
{
89+
public DateTime Date { get; set; }
90+
91+
public int TemperatureC { get; set; }
92+
93+
public string Summary { get; set; }
94+
95+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
96+
}
97+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using System.Text;
5+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
6+
using Microsoft.Extensions.DependencyInjection;
7+
8+
namespace BlazorAppTest
9+
{
10+
public class Program
11+
{
12+
public static async Task Main(string[] args)
13+
{
14+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
15+
builder.RootComponents.Add<App>("app");
16+
17+
builder.Services.AddBaseAddressHttpClient();
18+
19+
await builder.Build().RunAsync();
20+
}
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:7725",
7+
"sslPort": 44317
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"BlazorAppTest": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
}
25+
}
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">BlazorAppTest</a>
3+
<button class="navbar-toggler" @onclick="ToggleNavMenu">
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
12+
<span class="oi oi-home" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
@*<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="counter">
17+
<span class="oi oi-plus" aria-hidden="true"></span> Counter
18+
</NavLink>
19+
</li>
20+
<li class="nav-item px-3">
21+
<NavLink class="nav-link" href="fetchdata">
22+
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
23+
</NavLink>
24+
</li>*@
25+
</ul>
26+
</div>
27+
28+
@code {
29+
private bool collapseNavMenu = true;
30+
31+
private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
32+
33+
private void ToggleNavMenu()
34+
{
35+
collapseNavMenu = !collapseNavMenu;
36+
}
37+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@using System.Net.Http
2+
@using Microsoft.AspNetCore.Components.Forms
3+
@using Microsoft.AspNetCore.Components.Routing
4+
@using Microsoft.AspNetCore.Components.Web
5+
@using Microsoft.JSInterop
6+
@using BlazorAppTest
7+
@using BlazorAppTest.Shared

src-blazor/BlazorAppTest/wwwroot/css/bootstrap/bootstrap.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)