2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00

Generics workaround

This commit is contained in:
2022-06-05 02:06:59 +03:00
parent f1584b348d
commit 499f1e37d2
7 changed files with 89 additions and 78 deletions

View File

@ -284,7 +284,17 @@ public static class Codec
}
else
{
if (type.IsGenericType)
if (Codec.ImplementsInterface(type, typeof(IResource)))
{
var (hdr, data) = DataSerializer.ResourceComposer(valueOrSource, connection);
return TransmissionType.Compose(hdr, data);
}
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
{
var (hdr, data) = DataSerializer.RecordComposer(valueOrSource, connection);
return TransmissionType.Compose(hdr, data);
}
else if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
if (genericType == typeof(List<>))
@ -326,17 +336,7 @@ public static class Codec
return TransmissionType.Compose(hdr, data);
//}
}
else if (Codec.ImplementsInterface(type, typeof(IResource)))
{
var (hdr, data) = DataSerializer.ResourceComposer(valueOrSource, connection);
return TransmissionType.Compose(hdr, data);
}
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
{
var (hdr, data) = DataSerializer.RecordComposer(valueOrSource, connection);
return TransmissionType.Compose(hdr, data);
}
}
else if (type.IsEnum)
{
var (hdr, data) = DataSerializer.EnumComposer(valueOrSource, connection);

View File

@ -168,13 +168,11 @@ namespace Esiur.Data
public RepresentationType?[] SubTypes = new RepresentationType[3];
public static RepresentationType? FromType(Type type)//, bool forceNullable = false)
public static RepresentationType? FromType(Type type)
{
var nullable = false;// = forceNullable;
//if (!forceNullable)
//{
var nullable = false;
var nullType = System.Nullable.GetUnderlyingType(type);
if (nullType != null)
@ -182,9 +180,30 @@ namespace Esiur.Data
type = nullType;
nullable = true;
}
//}
if (type.IsGenericType)
if (type == typeof(IResource))
return new RepresentationType(RepresentationTypeIdentifier.Resource, nullable);
else if (type == typeof(IRecord) || type == typeof(Record))
return new RepresentationType(RepresentationTypeIdentifier.Record, nullable);
else if (type == typeof(Map<object, object>))
return new RepresentationType(RepresentationTypeIdentifier.Map, nullable);
else if (Codec.ImplementsInterface(type, typeof(IResource)))
{
return new RepresentationType(
RepresentationTypeIdentifier.TypedResource,
nullable,
TypeTemplate.GetTypeGuid(type)
);
}
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
{
return new RepresentationType(
RepresentationTypeIdentifier.TypedRecord,
nullable,
TypeTemplate.GetTypeGuid(type)
);
}
else if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
if (genericType == typeof(List<>))
@ -327,28 +346,6 @@ namespace Esiur.Data
}
}
else if (type == typeof(IResource))
return new RepresentationType(RepresentationTypeIdentifier.Resource, nullable);
else if (type == typeof(IRecord) || type == typeof(Record))
return new RepresentationType(RepresentationTypeIdentifier.Record, nullable);
else if (type == typeof(Map<object, object>))
return new RepresentationType(RepresentationTypeIdentifier.Map, nullable);
else if (Codec.ImplementsInterface(type, typeof(IResource)))
{
return new RepresentationType(
RepresentationTypeIdentifier.TypedResource,
nullable,
TypeTemplate.GetTypeGuid(type)
);
}
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
{
return new RepresentationType(
RepresentationTypeIdentifier.TypedRecord,
nullable,
TypeTemplate.GetTypeGuid(type)
);
}
else if (type.IsEnum)
{
return new RepresentationType(RepresentationTypeIdentifier.Enum, nullable, TypeTemplate.GetTypeGuid(type));