From 0c335c60231d2001f5d15fef998b5a38d88d6eb6 Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Mon, 11 Nov 2024 17:26:15 +0300 Subject: [PATCH] Interfaces --- Esiur/Data/RepresentationType.cs | 2 ++ Esiur/Esiur.csproj | 2 +- Esiur/Resource/Warehouse.cs | 3 +++ Test/IMyRecord.cs | 13 +++++++++++++ Test/MyService.cs | 1 + Test/Program.cs | 4 ++++ 6 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Test/IMyRecord.cs diff --git a/Esiur/Data/RepresentationType.cs b/Esiur/Data/RepresentationType.cs index 4950ff9..b1c8759 100644 --- a/Esiur/Data/RepresentationType.cs +++ b/Esiur/Data/RepresentationType.cs @@ -217,6 +217,8 @@ namespace Esiur.Data return new RepresentationType(RepresentationTypeIdentifier.Resource, nullable); else if (type == typeof(IRecord) || type == typeof(Record)) return new RepresentationType(RepresentationTypeIdentifier.Record, nullable); + else if (type.IsInterface) + return null; // other interfaces are not supported else if (type == typeof(Map)) return new RepresentationType(RepresentationTypeIdentifier.Map, nullable); else if (Codec.ImplementsInterface(type, typeof(IResource))) diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index e0d2f4b..f987ff9 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -5,7 +5,7 @@ Ahmed Kh. Zamil http://www.esiur.com true - 2.4.10 + 2.4.11 https://github.com/esiur/esiur-dotnet Ahmed Kh. Zamil diff --git a/Esiur/Resource/Warehouse.cs b/Esiur/Resource/Warehouse.cs index 4b02248..8bf3621 100644 --- a/Esiur/Resource/Warehouse.cs +++ b/Esiur/Resource/Warehouse.cs @@ -765,6 +765,9 @@ public static class Warehouse /// Resource template. public static TypeTemplate GetTemplateByType(Type type) { + if (!(type.IsClass || type.IsEnum)) + return null; + var baseType = ResourceProxy.GetBaseType(type); if (baseType == typeof(IResource) diff --git a/Test/IMyRecord.cs b/Test/IMyRecord.cs new file mode 100644 index 0000000..77e8174 --- /dev/null +++ b/Test/IMyRecord.cs @@ -0,0 +1,13 @@ +using Esiur.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Test +{ + public interface IMyRecord:IRecord + { + } +} diff --git a/Test/MyService.cs b/Test/MyService.cs index c043891..c1ecc58 100644 --- a/Test/MyService.cs +++ b/Test/MyService.cs @@ -128,6 +128,7 @@ public partial class MyService [Export] public IRecord[] RecordsArray => new IRecord[] { new MyRecord() { Id = 22, Name = "Test", Score = 22.1 } }; [Export] public List RecordsList => new() { new MyRecord() { Id = 22, Name = "Test", Score = 22.1 } }; + //[Export] public IMyRecord myrecord { get; set; } [Export] public MyResource[]? myResources; diff --git a/Test/Program.cs b/Test/Program.cs index 50ab39d..4d72c23 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -48,6 +48,7 @@ using System.Text; using Esiur.Security.Cryptography; using Esiur.Security.Membership; using Esiur.Net.Packets; +using System.Numerics; namespace Test { @@ -56,6 +57,9 @@ namespace Test { static async Task Main(string[] args) { + var rp = RepresentationType.FromType(typeof(IMyRecord)); + + var hhhh = Warehouse.GetTemplateByType(typeof(IMyRecord)); var a = new ECDH(); var b = new ECDH();