-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17f9810
commit d758ef8
Showing
15 changed files
with
132 additions
and
166 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
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
#nullable enable | ||
Microsoft.AspNetCore.Components.PersistentComponentState.TryTakeFromJson<TValue>(string! key, System.Text.Json.Serialization.Metadata.IJsonTypeInfoResolver! resolver, out TValue? instance) -> bool |
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
45 changes: 45 additions & 0 deletions
45
src/Components/Shared/src/JsonSerialization/JsonConverterFactoryTypeInfoResolver.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,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json.Serialization.Metadata; | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
|
||
// For custom converters that don't rely on serializing an object graph, | ||
// we can resolve the incoming type's JsonTypeInfo directly from the converter. | ||
// This skips extra work to collect metadata for the type that won't be used. | ||
internal sealed class JsonConverterFactoryTypeInfoResolver<T> : IJsonTypeInfoResolver | ||
{ | ||
public static readonly JsonConverterFactoryTypeInfoResolver<T> Instance = new(); | ||
|
||
private JsonConverterFactoryTypeInfoResolver() | ||
{ | ||
} | ||
|
||
public JsonTypeInfo? GetTypeInfo(Type type, JsonSerializerOptions options) | ||
{ | ||
if (type != typeof(T)) | ||
{ | ||
return null; | ||
} | ||
|
||
foreach (var converter in options.Converters) | ||
{ | ||
if (converter is not JsonConverterFactory factory || !factory.CanConvert(type)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (factory.CreateConverter(type, options) is not { } converterToUse) | ||
{ | ||
continue; | ||
} | ||
|
||
return JsonMetadataServices.CreateValueInfo<T>(options, converterToUse); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.