Skip to content

Commit

Permalink
Closing VS and again noticed uncommitted / pushed changes. Get btter …
Browse files Browse the repository at this point in the history
…at doing this in the moment.
  • Loading branch information
IEvangelist committed Mar 4, 2022
1 parent dfc5d49 commit ff744fc
Show file tree
Hide file tree
Showing 37 changed files with 542 additions and 273 deletions.
9 changes: 8 additions & 1 deletion blazorators.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.ExampleConsumer", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.LocalStorage.WebAssembly", "src\Blazor.LocalStorage.WebAssembly\Blazor.LocalStorage.WebAssembly.csproj", "{2F4EE253-7D56-4853-ADA7-4F2F6280C2D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.LocalStorage.Server", "src\Blazor.LocalStorage.Server\Blazor.LocalStorage.Server.csproj", "{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.LocalStorage.Server", "src\Blazor.LocalStorage.Server\Blazor.LocalStorage.Server.csproj", "{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.Serialization", "src\Blazor.Serialization\Blazor.Serialization.csproj", "{5E4658A7-4751-4F85-A558-12B8EBCA2BCA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -56,6 +58,10 @@ Global
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1}.Release|Any CPU.Build.0 = Release|Any CPU
{5E4658A7-4751-4F85-A558-12B8EBCA2BCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E4658A7-4751-4F85-A558-12B8EBCA2BCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E4658A7-4751-4F85-A558-12B8EBCA2BCA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E4658A7-4751-4F85-A558-12B8EBCA2BCA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -66,6 +72,7 @@ Global
{72914F05-4DF1-491C-B2E5-EFE9BB12FCC2} = {91A35318-B03F-4D41-AE18-2C21B9D9C3F3}
{2F4EE253-7D56-4853-ADA7-4F2F6280C2D2} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
{9AA2BB50-9F1A-43D0-BB6B-C3C4E9765BE1} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
{5E4658A7-4751-4F85-A558-12B8EBCA2BCA} = {537EB83C-6982-40B0-801A-479DF3B17DBE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3F86284A-32D2-4F79-B23C-7A0CB8775971}
Expand Down
26 changes: 15 additions & 11 deletions samples/Blazor.ExampleConsumer/Blazor.ExampleConsumer.csproj
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>
27 changes: 21 additions & 6 deletions samples/Blazor.ExampleConsumer/Pages/Counter.razor
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);
}
1 change: 1 addition & 0 deletions samples/Blazor.ExampleConsumer/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
@using Microsoft.JSInterop
@using Blazor.ExampleConsumer
@using Blazor.ExampleConsumer.Shared
@using Blazor.Serialization.Extensions;
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ namespace Microsoft.JSInterop;
/// <summary>
/// Source generated extension methods on the <see cref="IJSRuntime"/> implementation.
/// </summary>
[JSAutoGenericInterop(
[JSAutoInterop(
TypeName = "Storage",
PathFromWindow = "window.localStorage",
HostingModel = BlazorHostingModel.Server,
OnlyGeneratePureJS = true,
Url = "https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage",
GenericMethodDescriptors = new[]
{
"getItem",
"setItem:value"
})]
Url = "https://developer.mozilla.org/docs/Web/API/Window/localStorage")]
public static partial class AsynchronousLocalStorageExtensions
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<ProjectReference Include="..\Blazor.SourceGenerators\Blazor.SourceGenerators.csproj"
OutputItemType="Analyzer"
SetTargetFramework="TargetFramework=netstandard2.0"
ReferenceOutputAssembly="true" />
ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup Label="Files">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<IncludeSymbols>false</IncludeSymbols>
<IncludeSource>false</IncludeSource>
<RootNamespace>Blazor.LocalStorage.WebAssembly</RootNamespace>
<NoWarn>NU5125;NU5039;MSB3243</NoWarn>
<NoWarn>NU5125;NU5039;</NoWarn>
<Optimize Condition="'$(Configuration)'=='Release'">true</Optimize>
<RepositoryUrl>https://github.com/IEvangelist/blazorators</RepositoryUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand Down Expand Up @@ -62,10 +62,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Blazor.SourceGenerators\Blazor.SourceGenerators.csproj"
OutputItemType="Analyzer"
SetTargetFramework="TargetFramework=netstandard2.0"
ReferenceOutputAssembly="true" />
<ProjectReference Include="..\Blazor.Serialization\Blazor.Serialization.csproj" />
<ProjectReference Include="..\Blazor.SourceGenerators\Blazor.SourceGenerators.csproj" OutputItemType="Analyzer" SetTargetFramework="TargetFramework=netstandard2.0" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup Label="Files">
Expand Down
14 changes: 4 additions & 10 deletions src/Blazor.LocalStorage.WebAssembly/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ namespace Microsoft.Extensions.DependencyInjection;
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds the ability to either <c>@inject</c>
/// (or <c>[Inject]</c>) the <c>IJSInProcessRuntime</c> type.
/// </summary>
[Obsolete("Call AddInProcessJavaScript instead.")]
public static IServiceCollection AddWebAssemblyLocalStorage(
this IServiceCollection services) =>
services.AddInProcessJavaScript();

/// <summary>
/// Adds the ability to either <c>@inject</c>
/// (or <c>[Inject]</c>) the <c>IJSInProcessRuntime</c> type.
Expand All @@ -28,5 +19,8 @@ public static IServiceCollection AddInProcessJavaScript(
this IServiceCollection services) =>
services.AddScoped<IJSInProcessRuntime>(
serviceProvider =>
(IJSInProcessRuntime)serviceProvider.GetRequiredService<IJSRuntime>());
(IJSInProcessRuntime)serviceProvider.GetRequiredService<IJSRuntime>())
.AddScoped<IJSUnmarshalledRuntime>(
serviceProvider =>
(IJSUnmarshalledRuntime)serviceProvider.GetRequiredService<IJSRuntime>());
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.JSInterop;
PathFromWindow = "window.localStorage",
HostingModel = BlazorHostingModel.WebAssembly,
OnlyGeneratePureJS = true,
Url = "https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage",
Url = "https://developer.mozilla.org/docs/Web/API/Window/localStorage",
GenericMethodDescriptors = new[]
{
"getItem",
Expand Down
67 changes: 67 additions & 0 deletions src/Blazor.Serialization/Blazor.Serialization.csproj
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 src/Blazor.Serialization/Extensions/SerializationExtensions.cs
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);
}
6 changes: 6 additions & 0 deletions src/Blazor.Serialization/GlobalUsings.cs
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;
Loading

0 comments on commit ff744fc

Please sign in to comment.