Skip to content

Commit 147b5bc

Browse files
Copilotjaviercn
andcommitted
Make PersistAsync and TryTake methods internal for custom serializers
Co-authored-by: javiercn <[email protected]>
1 parent 6f2f33c commit 147b5bc

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

src/Components/Components/src/PersistentComponentState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ internal void PersistAsJson(string key, object instance, [DynamicallyAccessedMem
119119
/// <param name="instance">The instance to persist.</param>
120120
/// <param name="serializer">The custom serializer to use for serialization.</param>
121121
/// <param name="cancellationToken">A cancellation token that can be used to cancel the serialization operation.</param>
122-
public async Task PersistAsync<TValue>(string key, TValue instance, IPersistentComponentStateSerializer<TValue> serializer, CancellationToken cancellationToken = default)
122+
internal async Task PersistAsync<TValue>(string key, TValue instance, IPersistentComponentStateSerializer<TValue> serializer, CancellationToken cancellationToken = default)
123123
{
124124
ArgumentNullException.ThrowIfNull(key);
125125
ArgumentNullException.ThrowIfNull(serializer);
@@ -194,7 +194,7 @@ internal bool TryTakeFromJson(string key, [DynamicallyAccessedMembers(JsonSerial
194194
/// <param name="serializer">The custom serializer to use for deserialization.</param>
195195
/// <param name="instance">The persisted instance.</param>
196196
/// <returns><c>true</c> if the state was found; <c>false</c> otherwise.</returns>
197-
public bool TryTake<TValue>(string key, IPersistentComponentStateSerializer<TValue> serializer, [MaybeNullWhen(false)] out TValue instance)
197+
internal bool TryTake<TValue>(string key, IPersistentComponentStateSerializer<TValue> serializer, [MaybeNullWhen(false)] out TValue instance)
198198
{
199199
ArgumentNullException.ThrowIfNull(key);
200200
ArgumentNullException.ThrowIfNull(serializer);

src/Components/Components/src/PersistentStateValueProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public bool CanSupplyValue(in CascadingParameterInfo parameterInfo)
4949
if (customSerializer != null)
5050
{
5151
// Use reflection to call the generic TryTake method with the custom serializer
52-
var tryTakeMethod = typeof(PersistentComponentState).GetMethod(nameof(PersistentComponentState.TryTake), BindingFlags.Instance | BindingFlags.Public, [typeof(string), serializerType, parameterInfo.PropertyType.MakeByRefType()]);
52+
var tryTakeMethod = typeof(PersistentComponentState).GetMethod(nameof(PersistentComponentState.TryTake), BindingFlags.Instance | BindingFlags.NonPublic, [typeof(string), serializerType, parameterInfo.PropertyType.MakeByRefType()]);
5353
if (tryTakeMethod != null)
5454
{
5555
var parameters = new object?[] { storageKey, customSerializer, null };
@@ -86,7 +86,7 @@ public void Subscribe(ComponentState subscriber, in CascadingParameterInfo param
8686
if (customSerializer != null)
8787
{
8888
// Use reflection to call the generic PersistAsync method with the custom serializer
89-
var persistMethod = typeof(PersistentComponentState).GetMethod(nameof(PersistentComponentState.PersistAsync), BindingFlags.Instance | BindingFlags.Public, [typeof(string), propertyType, serializerType, typeof(CancellationToken)]);
89+
var persistMethod = typeof(PersistentComponentState).GetMethod(nameof(PersistentComponentState.PersistAsync), BindingFlags.Instance | BindingFlags.NonPublic, [typeof(string), propertyType, serializerType, typeof(CancellationToken)]);
9090
if (persistMethod != null)
9191
{
9292
var task = (Task)persistMethod.Invoke(state, [storageKey, property, customSerializer, CancellationToken.None])!;

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ virtual Microsoft.AspNetCore.Components.Rendering.ComponentState.GetComponentKey
2424
Microsoft.AspNetCore.Components.IPersistentComponentStateSerializer<T>
2525
Microsoft.AspNetCore.Components.IPersistentComponentStateSerializer<T>.PersistAsync(T value, System.Buffers.IBufferWriter<byte>! writer, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
2626
Microsoft.AspNetCore.Components.IPersistentComponentStateSerializer<T>.Restore(System.Buffers.ReadOnlySequence<byte> data) -> T
27-
Microsoft.AspNetCore.Components.PersistentComponentState.PersistAsync<TValue>(string! key, TValue instance, Microsoft.AspNetCore.Components.IPersistentComponentStateSerializer<TValue>! serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
28-
Microsoft.AspNetCore.Components.PersistentComponentState.TryTake<TValue>(string! key, Microsoft.AspNetCore.Components.IPersistentComponentStateSerializer<TValue>! serializer, out TValue instance) -> bool

0 commit comments

Comments
 (0)