Я сам не знаю как и что, но оно работает как то

This commit is contained in:
2025-03-01 16:40:40 +03:00
parent af65f22aa9
commit 8f891ff59e
8 changed files with 128 additions and 82 deletions
+7 -5
View File
@@ -183,7 +183,7 @@ namespace mROA.Cbor
if (type == typeof(ulong))
return reader.ReadUInt64();
return reader.ReadInt32();
return reader.ReadUInt64();
case CborReaderState.ByteString:
if (type == typeof(Guid))
return new Guid(reader.ReadByteString());
@@ -284,6 +284,7 @@ namespace mROA.Cbor
private object ReadObject(CborReader reader, Type type, IEndPointContext? context)
{
if (type == typeof(object))
{
return new PreParsedValue(ReadList(reader, null, context) as List<object>);
@@ -311,12 +312,13 @@ namespace mROA.Cbor
private void FillObject(object obj, Type type, CborReader reader, IEndPointContext? context)
{
var propertyInfos = type.GetProperties();
var properties = FilterProperties(propertyInfos);
var length = reader.ReadStartArray();
try
{
var propertyInfos = type.GetProperties();
var properties = FilterProperties(propertyInfos);
var length = reader.ReadStartArray();
#if TRACE
Console.WriteLine($"Reading list of {length} objects, {properties.Count} properties found");
#endif
@@ -342,7 +344,7 @@ namespace mROA.Cbor
public static List<PropertyInfo> FilterProperties(PropertyInfo[] properties)
{
var finalProperties = new List<PropertyInfo>(properties.Length);
foreach (var property in properties)
foreach (var property in properties.Where(i => i.CanWrite && i.CanRead))
{
if (property.GetCustomAttribute<SerializationIgnoreAttribute>() == null)
finalProperties.Add(property);
+27 -5
View File
@@ -5,13 +5,18 @@ using mROA.Implementation;
namespace mROA.Cbor
{
public class PreParsedValue
public interface IPreParsedValue
{
public List<object> Properties { get; set; }
object? ToObject(Type type, IEndPointContext? context);
}
public class PreParsedValue : IPreParsedValue
{
private List<object> _properties { get; set; }
public PreParsedValue(List<object> properties)
{
Properties = properties;
_properties = properties;
}
public object? ToObject(Type type, IEndPointContext? context)
@@ -24,14 +29,31 @@ namespace mROA.Cbor
{
sharedObject.EndPointContext = context;
}
var properties = CborSerializationToolkit.FilterProperties(type.GetProperties());
for (var index = 0; index < properties.Count; index++)
{
var property = properties[index];
property.SetValue(instance, Properties[index]);
property.SetValue(instance, _properties[index] is IPreParsedValue ppv ? ppv.ToObject(property.PropertyType, context) : _properties[index]);
}
return instance;
}
}
public class ParsedValue : IPreParsedValue
{
public ParsedValue(object? value)
{
_value = value;
}
private object? _value;
public object? ToObject(Type type, IEndPointContext? context)
{
return _value;
}
}
}