Исправления чтения списков
This commit is contained in:
@@ -11,7 +11,7 @@ using mROA.Implementation.Attributes;
|
||||
|
||||
namespace mROA.Cbor
|
||||
{
|
||||
public class CborSerializaitonToolkit : IContextualSerializationToolKit
|
||||
public class CborSerializationToolkit : IContextualSerializationToolKit
|
||||
{
|
||||
public byte[] Serialize(object objectToSerialize, IEndPointContext context)
|
||||
{
|
||||
@@ -122,9 +122,6 @@ namespace mROA.Cbor
|
||||
|
||||
private void WriteList(IList list, CborWriter writer, IEndPointContext context)
|
||||
{
|
||||
|
||||
|
||||
|
||||
writer.WriteStartArray(list.Count);
|
||||
|
||||
foreach (var element in list)
|
||||
@@ -194,7 +191,7 @@ namespace mROA.Cbor
|
||||
if (type.IsSubclassOf(typeof(ISharedObject)))
|
||||
return ReadSharedObject(reader, type, context);
|
||||
|
||||
if (type.IsSubclassOf(typeof(IList)) || type.IsArray)
|
||||
if (typeof(IList).IsAssignableFrom(type) || type.IsArray)
|
||||
return ReadList(reader, type, context);
|
||||
|
||||
return ReadObject(reader, type, context);
|
||||
@@ -216,21 +213,27 @@ namespace mROA.Cbor
|
||||
var length = reader.ReadStartArray();
|
||||
if (length != null)
|
||||
{
|
||||
var values = new object[length.Value];
|
||||
|
||||
Type elementType = typeof(object);
|
||||
var elementType = typeof(object);
|
||||
|
||||
if (type is { IsArray: true })
|
||||
elementType = type.GetElementType();
|
||||
else if (typeof(IList).IsAssignableFrom(type))
|
||||
elementType = type.GetGenericArguments()[0];
|
||||
|
||||
Array values = Array.CreateInstance(elementType, length.Value);
|
||||
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
values[i] = ReadData(reader, elementType, context);
|
||||
values.SetValue(ReadData(reader, elementType, context), i);
|
||||
}
|
||||
|
||||
reader.ReadEndArray();
|
||||
return values;
|
||||
}
|
||||
|
||||
reader.ReadEndArray();
|
||||
|
||||
return Array.Empty<object>();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ public class CborTest
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_complexTestObject = new ()
|
||||
_basicCollectionElement = new() { A = 567565, B = "test text", C = 2.781f };
|
||||
|
||||
_complexTestObject = new ComplexTestObject
|
||||
{
|
||||
IntValue = 123,
|
||||
DoubleValue = 3.14159,
|
||||
@@ -26,8 +28,7 @@ public class CborTest
|
||||
],
|
||||
IntArray = [1, 4, 8, 16, 87]
|
||||
};
|
||||
_basicCollectionElement = new() { A = 567565, B = "test text", C = 2.781f };
|
||||
_serializationToolKit = new CborSerializaitonToolkit();
|
||||
_serializationToolKit = new CborSerializationToolkit();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -69,7 +70,7 @@ public class CborTest
|
||||
public double DoubleValue { get; set; }
|
||||
public string StringValue { get; set; }
|
||||
public int[] IntArray { get; set; }
|
||||
public BasicCollectionElement[] CollectionElements { get; set; }
|
||||
public List<BasicCollectionElement> CollectionElements { get; set; }
|
||||
|
||||
protected bool Equals(ComplexTestObject other)
|
||||
{
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
IContextRepository RealRepository { get; }
|
||||
IContextRepository RemoteRepository { get; }
|
||||
int HostId { get; }
|
||||
int OwnerId { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation
|
||||
{
|
||||
public class EndPointContext : IEndPointContext
|
||||
{
|
||||
public Func<int> OwnerFunc;
|
||||
public IContextRepository RealRepository { get; set; }
|
||||
public IContextRepository RemoteRepository { get; set; }
|
||||
public int HostId { get; set; }
|
||||
public int OwnerId
|
||||
{
|
||||
get => OwnerFunc();
|
||||
set
|
||||
{
|
||||
OwnerFunc = () => value;
|
||||
} }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
using mROA.Abstract;
|
||||
|
||||
// ReSharper disable UnusedMember.Global
|
||||
#pragma warning disable CS8618, CS9264
|
||||
|
||||
@@ -20,7 +21,8 @@ namespace mROA.Implementation
|
||||
|
||||
public static IContextRepository RemoteEndpointContextRepository
|
||||
{
|
||||
get => _remoteEndpointContextRepository ?? throw new NullReferenceException("RemoteEndpointContextRepository is null");
|
||||
get => _remoteEndpointContextRepository ??
|
||||
throw new NullReferenceException("RemoteEndpointContextRepository is null");
|
||||
set => _remoteEndpointContextRepository = value;
|
||||
}
|
||||
|
||||
@@ -29,7 +31,6 @@ namespace mROA.Implementation
|
||||
get => _ownershipRepository ?? throw new NullReferenceException("OwnershipRepository is null");
|
||||
set => _ownershipRepository = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface ISharedObject
|
||||
@@ -105,6 +106,12 @@ namespace mROA.Implementation
|
||||
public static implicit operator SharedObject<T>(T value) =>
|
||||
new(value);
|
||||
|
||||
public IEndPointContext EndPointContext { get; set; }
|
||||
public IEndPointContext EndPointContext { get; set; } = new EndPointContext
|
||||
{
|
||||
RealRepository = TransmissionConfig.RealContextRepository,
|
||||
RemoteRepository = TransmissionConfig.RemoteEndpointContextRepository,
|
||||
HostId = TransmissionConfig.OwnershipRepository.GetHostOwnershipId(),
|
||||
OwnerFunc = TransmissionConfig.OwnershipRepository.GetOwnershipId
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user