From da28cdeba700a3dfbc1dee4778400532101c468f Mon Sep 17 00:00:00 2001 From: Gustavo Brown Date: Fri, 29 Jul 2022 12:52:25 -0300 Subject: [PATCH 1/2] fix GetEnumerableType to work with Net6 and to support types implementing multiple interfaces --- .../dotnetframework/GxClasses/Domain/GxCollections.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs index c05addf7d..310c5390a 100644 --- a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs +++ b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs @@ -2684,10 +2684,12 @@ static public object ConvertToInternal(Type to, Object i) static Type GetEnumerableType(Type type) { -#if !NETCORE - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)) - return type.GetGenericArguments()[0]; -#endif + if (type.IsGenericType) + { + return type.GetInterfaces() + .FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>)) + ?.GetGenericArguments()[0]; + } return null; } From ff1786951250289359490c856a42ef99802bfe1d Mon Sep 17 00:00:00 2001 From: cmurialdo Date: Thu, 20 Oct 2022 14:10:01 -0300 Subject: [PATCH 2/2] Compatibility fix at ConvertToInternal: do not create a copy of the object when the target type and object type are the same. Issue:99361 --- dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs index 310c5390a..81af90fb7 100644 --- a/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs +++ b/dotnet/src/dotnetframework/GxClasses/Domain/GxCollections.cs @@ -2663,6 +2663,8 @@ static public object ConvertToInternal(Type to, Object i) { o = convertFuncts[to].ConvertToList(i); } + else if (to.IsInstanceOfType(i)) + o = i; else if (ienumerableType != null) { IList lst = (IList)Activator.CreateInstance((typeof(List<>).MakeGenericType(ienumerableType))); @@ -2670,8 +2672,6 @@ static public object ConvertToInternal(Type to, Object i) lst.Add(item); o = lst; } - else if (to.IsInstanceOfType(i)) - o = i; else { IList l = (IList)Activator.CreateInstance(to);