Skip to content

Commit

Permalink
- adds support for trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Oct 23, 2023
1 parent 24a239f commit d0a036c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text.Json.Serialization;

namespace Microsoft.Graph.Cli.Core.Configuration;

/// <summary>
Expand All @@ -10,3 +12,8 @@ public class ConfigurationRoot
/// </summary>
public AuthenticationOptions AuthenticationOptions { get; set; } = new AuthenticationOptions();
}

[JsonSerializable(typeof(ConfigurationRoot))]
internal partial class SourceGenerationContext : JsonSerializerContext
{
}
4 changes: 2 additions & 2 deletions src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void DeleteAuthenticationRecord()

try
{
return await JsonSerializer.DeserializeAsync<Configuration.ConfigurationRoot>(fileStream, cancellationToken: cancellationToken);
return await JsonSerializer.DeserializeAsync(fileStream, SourceGenerationContext.Default.ConfigurationRoot, cancellationToken: cancellationToken).ConfigureAwait(false);
}
catch (Exception)
{
Expand All @@ -188,7 +188,7 @@ private async Task WriteConfigurationAsync(string path, ConfigurationRoot config
try
{
using FileStream fileStream = File.Open(path, FileMode.Create, FileAccess.Write);
await JsonSerializer.SerializeAsync(fileStream, configuration, cancellationToken: cancellationToken);
await JsonSerializer.SerializeAsync(fileStream, configuration, SourceGenerationContext.Default.ConfigurationRoot, cancellationToken: cancellationToken).ConfigureAwait(false);
}
catch (DirectoryNotFoundException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<DebugType>embedded</DebugType>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>preview.8</VersionSuffix>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/sample/sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);CS8669</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,4 +21,4 @@
<ProjectReference Include="..\Microsoft.Graph.Cli.Core\Microsoft.Graph.Cli.Core.csproj" />
</ItemGroup>

</Project>
</Project>

0 comments on commit d0a036c

Please sign in to comment.