Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>9.0.8</Version>
<Version>9.0.10</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public virtual bool TryConvertTo(ReadOnlyMemory<byte> data, [NotNullWhen(true)]
}
catch (Exception ex)
{
SocketLogging.LogError(ex, "DataConverter TryConvertTo failed");
SocketLogging.LogError(ex, $"DataConverter {nameof(TryConvertTo)} failed");
}

return ret;
}

Expand All @@ -64,8 +63,6 @@ protected virtual bool Parse(ReadOnlyMemory<byte> data, TEntity entity)
var ret = false;
if (entity != null)
{
var unuseProperties = new List<PropertyInfo>(32);

// 通过 SocketDataPropertyConverterAttribute 特性获取属性转换器
var properties = entity.GetType().GetProperties().Where(p => p.CanWrite).ToList();
foreach (var p in properties)
Expand All @@ -81,10 +78,8 @@ protected virtual bool Parse(ReadOnlyMemory<byte> data, TEntity entity)
}
}
}

ret = true;
}

return ret;
}

Expand All @@ -95,7 +90,6 @@ protected virtual bool Parse(ReadOnlyMemory<byte> data, TEntity entity)
{
attr = v;
}

return attr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ static class DataPropertyExtensions
var type = attribute.Type;
if (type != null)
{
if (type == typeof(byte[]))
if (type == typeof(byte))
{
converter = new DataByteConverter();
}
else if (type == typeof(byte[]))
{
converter = new DataByteArrayConverter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 bool 数据转换器
/// Socket 数据转换为 bool 数据转换器
/// </summary>
public class DataBoolConverter : IDataPropertyConverter
{
Expand All @@ -16,7 +16,7 @@ public class DataBoolConverter : IDataPropertyConverter
public object? Convert(ReadOnlyMemory<byte> data)
{
var ret = false;
if (data.Length == 1)
if (data.Length > 0)
{
ret = data.Span[0] != 0x00;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 byte[] 数组转换器
/// Socket 数据转换为 byte[] 数组转换器
/// </summary>
public class DataByteArrayConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 数据转换为 byte 转换器
/// </summary>
public class DataByteConverter : IDataPropertyConverter
{
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="data"></param>
public object? Convert(ReadOnlyMemory<byte> data)
{
Comment thread
ArgoZhang marked this conversation as resolved.
return data.Length > 0 ? data.Span[0] : 0x0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 double 数据大端转换器
/// Socket 数据转换为 double 数据大端转换器
/// </summary>
public class DataDoubleBigEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 double 数据小端转换器
/// Socket 数据转换为 double 数据小端转换器
/// </summary>
public class DataDoubleLittleEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 Enum 数据转换器
/// Socket 数据转换为 Enum 数据转换器
/// </summary>
public class DataEnumConverter(Type? type) : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 short 数据大端转换器
/// Socket 数据转换为 short 数据大端转换器
/// </summary>
public class DataInt16BigEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 short 数据小端转换器
/// Socket 数据转换为 short 数据小端转换器
/// </summary>
public class DataInt16LittleEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 int 数据大端转换器
/// Socket 数据转换为 int 数据大端转换器
/// </summary>
public class DataInt32BigEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 int 数据小端转换器
/// Socket 数据转换为 int 数据小端转换器
/// </summary>
public class DataInt32LittleEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 long 数据大端转换器
/// Socket 数据转换为 long 数据大端转换器
/// </summary>
public class DataInt64BigEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 long 数据小端转换器
/// Socket 数据转换为 long 数据小端转换器
/// </summary>
public class DataInt64LittleEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 float 数据大端转换器
/// Socket 数据转换为 float 数据大端转换器
/// </summary>
public class DataSingleBigEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 float 数据小端转换器
/// Socket 数据转换为 float 数据小端转换器
/// </summary>
public class DataSingleLittleEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 string 数据转换器
/// Socket 数据转换为 string 数据转换器
/// </summary>
public class DataStringConverter(string? encodingName) : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 ushort 数据大端转换器
/// Socket 数据转换为 ushort 数据大端转换器
/// </summary>
public class DataUInt16BigEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 ushort 数据小端转换器
/// Socket 数据转换为 ushort 数据小端转换器
/// </summary>
public class DataUInt16LittleEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 uint 数据大端转换器
/// Socket 数据转换为 uint 数据大端转换器
/// </summary>
public class DataUInt32BigEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 uint 数据小端转换器
/// Socket 数据转换为 uint 数据小端转换器
/// </summary>
public class DataUInt32LittleEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 ulong 数据大端转换器
/// Socket 数据转换为 ulong 数据大端转换器
/// </summary>
public class DataUInt64BigEndianConverter : IDataPropertyConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace BootstrapBlazor.Socket.DataConverters;

/// <summary>
/// Sokcet 数据转换为 ulong 数据小端转换器
/// Socket 数据转换为 ulong 数据小端转换器
/// </summary>
public class DataUInt64LittleEndianConverter : IDataPropertyConverter
{
Expand Down
1 change: 0 additions & 1 deletion test/UnitTestTcpSocket/TcpSocketFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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/

using BootstrapBlazor.Socket.Logging;
using Microsoft.Extensions.Logging;
using System.Buffers;
using System.Net;
Expand Down