-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closing VS and again noticed uncommitted / pushed changes. Get btter …
…at doing this in the moment.
- Loading branch information
1 parent
dfc5d49
commit ff744fc
Showing
37 changed files
with
542 additions
and
273 deletions.
There are no files selected for viewing
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
26 changes: 15 additions & 11 deletions
26
samples/Blazor.ExampleConsumer/Blazor.ExampleConsumer.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.2" PrivateAssets="all" /> | ||
<PackageReference Include="Blazor.LocalStorage.WebAssembly" Version="1.0.3" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.2" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Blazor.LocalStorage.WebAssembly\Blazor.LocalStorage.WebAssembly.csproj" /> | ||
<ProjectReference Include="..\..\src\Blazor.Serialization\Blazor.Serialization.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
@page "/counter" | ||
@inject IJSInProcessRuntime JavaScript | ||
@inject NavigationManager Nav | ||
@implements IDisposable | ||
|
||
<PageTitle>Counter (@_currentCount)</PageTitle> | ||
|
||
<h1>Counter</h1> | ||
|
||
<p role="status">Current count: @_currentCount</p> | ||
|
||
<button class="btn btn-primary" @onclick="IncrementCount">Increment</button> | ||
<input type="checkbox" @bind=_isDisabled /> Disabled: @_isDisabled | ||
|
||
<button class="btn btn-primary" | ||
disabled=@_isDisabled @onclick="IncrementCount">Increment</button> | ||
|
||
@code { | ||
private int _currentCount = 0; | ||
private bool _isDisabled = true; | ||
|
||
private void IncrementCount() => JavaScript.SetItem("CounterValue", (++ _currentCount).ToString()); | ||
private void IncrementCount() => | ||
JavaScript.SetItem<int>("CounterValue", ++_currentCount); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
|
||
if (JavaScript.GetItem("CounterValue") is { } count && int.TryParse(count, out var currentCount)) | ||
{ | ||
_currentCount = currentCount; | ||
} | ||
Nav.LocationChanged += OnLocationChanged; | ||
|
||
_isDisabled = JavaScript.GetItem<bool>("Disabled"); | ||
_currentCount = JavaScript.GetItem<int>("CounterValue"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Nav.LocationChanged -= OnLocationChanged; | ||
} | ||
|
||
void OnLocationChanged(object? sender, LocationChangedEventArgs args) => | ||
JavaScript.SetItem<bool>("Disabled", _isDisabled); | ||
} |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>true</ImplicitUsings> | ||
<Description>A C# class library providing light-weight serialization functionality.</Description> | ||
<Copyright>Copyright © David Pine. All rights reserved. Licensed under the MIT License.</Copyright> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
<CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMdd))</CurrentDate> | ||
<ClientVersion Condition=" '$(IsPreview)' != 'true' ">$(ClientOfficialVersion)</ClientVersion> | ||
<ClientVersion Condition=" '$(IsPreview)' == 'true' ">$(ClientPreviewVersion)</ClientVersion> | ||
<VersionSuffix Condition=" '$(IsNightly)' == 'true' ">nightly-$(CurrentDate)</VersionSuffix> | ||
<VersionSuffix Condition=" '$(IsPreview)' == 'true' ">preview</VersionSuffix> | ||
<Version Condition=" '$(VersionSuffix)' == '' ">$(ClientVersion)</Version> | ||
<Version Condition=" '$(VersionSuffix)' != '' ">$(ClientVersion)-$(VersionSuffix)</Version> | ||
<FileVersion>$(ClientVersion)</FileVersion> | ||
<Authors>David Pine</Authors> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<AssemblyName>Blazor.Serialization</AssemblyName> | ||
<Title>Blazor serialization class library</Title> | ||
<PackageId>Blazor.Serialization</PackageId> | ||
<PackageTags>dotnet;dotnetcore;csharp;blazor;webassembly;wasm;generators;sourcegen;roslyn;</PackageTags> | ||
<PackageReleaseNotes></PackageReleaseNotes> | ||
<PackageProjectUrl>https://github.com/IEvangelist/blazorators</PackageProjectUrl> | ||
<PublishRepositoryUrl Condition=" '$(ProjectRef)' != 'True' ">true</PublishRepositoryUrl> | ||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<ShippingScope>External</ShippingScope> | ||
<SigningType>Product</SigningType> | ||
<DebugType>embedded</DebugType> | ||
<IncludeSymbols>false</IncludeSymbols> | ||
<IncludeSource>false</IncludeSource> | ||
<RootNamespace>Blazor.Serialization</RootNamespace> | ||
<NoWarn>NU5125;NU5039;</NoWarn> | ||
<Optimize Condition="'$(Configuration)'=='Release'">true</Optimize> | ||
<RepositoryUrl>https://github.com/IEvangelist/blazorators</RepositoryUrl> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<RepositoryType>git</RepositoryType> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<IsPackable>true</IsPackable> | ||
<PackageIcon>logo.png</PackageIcon> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="MinVer" Version="2.5.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup Label="Files"> | ||
<None Include="..\..\LICENSE" Pack="true" PackagePath="\" /> | ||
<None Include="..\..\README.md" Pack="true" PackagePath="\" /> | ||
<None Include="..\..\logo.png" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
35 changes: 35 additions & 0 deletions
35
src/Blazor.Serialization/Extensions/SerializationExtensions.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Blazor.Serialization.Extensions; | ||
|
||
/// <summary> | ||
/// JSON serialization extension methods. | ||
/// </summary> | ||
public static class SerializationExtensions | ||
{ | ||
private static readonly JsonSerializerOptions _defaultOptions = new() | ||
{ | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
PropertyNameCaseInsensitive = true, | ||
NumberHandling = JsonNumberHandling.AllowReadingFromString, | ||
Converters = | ||
{ | ||
new JsonStringEnumConverter() | ||
} | ||
}; | ||
|
||
/// <inheritdoc cref="Deserialize{TValue}(string, JsonSerializerOptions?)" /> | ||
public static TResult? FromJson<TResult>( | ||
this string? json, | ||
JsonSerializerOptions? options = null) => | ||
json is { Length: > 0 } | ||
? Deserialize<TResult>(json, options ?? _defaultOptions) | ||
: default; | ||
|
||
/// <inheritdoc cref="Serialize{TValue}(TValue, JsonSerializerOptions?)" /> | ||
public static string ToJson<T>( | ||
this T value, | ||
JsonSerializerOptions? options = null) => | ||
Serialize(value, options ?? _defaultOptions); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
global using System.Text.Json; | ||
global using System.Text.Json.Serialization; | ||
global using static System.Text.Json.JsonSerializer; |
Oops, something went wrong.