-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathIDataConverter.cs
More file actions
31 lines (27 loc) · 1.49 KB
/
IDataConverter.cs
File metadata and controls
31 lines (27 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
namespace BootstrapBlazor.Socket.DataConverters;
/// <summary>
/// Socket 数据转换器接口
/// </summary>
public interface IDataConverter
{
}
/// <summary>
/// Defines a method to convert raw socket data into a specified entity type.
/// </summary>
/// <typeparam name="TEntity">The type of entity to convert the data into.</typeparam>
public interface IDataConverter<TEntity> : IDataConverter
{
/// <summary>
/// Attempts to convert the specified data to an instance of <typeparamref name="TEntity"/>.
/// </summary>
/// <remarks>This method does not throw an exception if the conversion fails. Instead, it returns <see
/// langword="false"/> and sets <paramref name="entity"/> to <see langword="null"/>.</remarks>
/// <param name="data">The data to be converted, represented as a read-only memory block of bytes.</param>
/// <param name="entity">When this method returns, contains the converted <typeparamref name="TEntity"/> if the conversion succeeded;
/// otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if the conversion was successful; otherwise, <see langword="false"/>.</returns>
bool TryConvertTo(ReadOnlyMemory<byte> data, [NotNullWhen(true)] out TEntity? entity);
}