From b462a56ca8bfc38b293c9490b9c9501a3308a69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Thu, 3 Apr 2025 10:44:12 +0100 Subject: [PATCH 1/5] Remove condition on IsOmNamespace for when to call the Base.Create.Type method That method is handlign far more than just oM classes. Should be used for other types as well. Only keeping the check for IsEngineNamespace as that still should work fine --- Serialiser_Engine/Compute/Deserialise/Type.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Serialiser_Engine/Compute/Deserialise/Type.cs b/Serialiser_Engine/Compute/Deserialise/Type.cs index 08d5af3bb..331e5887a 100644 --- a/Serialiser_Engine/Compute/Deserialise/Type.cs +++ b/Serialiser_Engine/Compute/Deserialise/Type.cs @@ -38,7 +38,7 @@ public static partial class Compute /*******************************************/ /**** Private Methods ****/ /*******************************************/ - + private static Type DeserialiseType(this BsonValue bson, Type value, string version, bool isUpgraded) { // Handle the case where the type is represented as a string @@ -146,16 +146,10 @@ private static Type GetTypeFromName(string fullName) Type type = null; if (fullName == "T") return null; - if (fullName.IsOmNamespace()) - type = Base.Create.Type(fullName, true, true); else if (fullName.IsEngineNamespace()) type = Base.Create.EngineType(fullName, true, true); else - { - type = Type.GetType(fullName); - if (type == null) - type = System.Type.GetType(Base.Query.UnqualifiedName(fullName)); - } + type = Base.Create.Type(fullName, true, true); //Use for all cases except engine methods as method able to handle both oM, and system types, as well as adapter. Also this method is called no matter what if the type is serialised as a string rather than document in this file if (type == null) { From aa59b81d2160bdabe88dd14859678026f2ebfbef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Thu, 3 Apr 2025 10:45:01 +0100 Subject: [PATCH 2/5] Handle reftypes Changing from checking that the string ends with & to instead contains to handle the case of qualified ref type --- BHoM_Engine/Create/Type/Type.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BHoM_Engine/Create/Type/Type.cs b/BHoM_Engine/Create/Type/Type.cs index 6bd9c9a64..284a3b3d7 100644 --- a/BHoM_Engine/Create/Type/Type.cs +++ b/BHoM_Engine/Create/Type/Type.cs @@ -67,9 +67,9 @@ public static Type Type(string name, bool silent = false, bool takeFirstIfMultip if (type == null) type = System.Type.GetType(unQualifiedName); //Fallback for when deserialising a type from a later net runtime to a lower net runtime. Can be critical when going between softwares of different net runtimes. - if (type == null && name.EndsWith("&")) + if (type == null && name.Contains("&")) { - type = Type(name.TrimEnd(new char[] { '&' }), true); + type = Type(name.Replace("&", ""), silent, takeFirstIfMultiple); if (type != null) type = type.MakeByRefType(); } From f7c3060b8327ac9f3eab5fb15188bc1bce6be612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Thu, 3 Apr 2025 10:46:03 +0100 Subject: [PATCH 3/5] Handle ref type for generic type creation --- BHoM_Engine/Create/Type/GenericType.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/BHoM_Engine/Create/Type/GenericType.cs b/BHoM_Engine/Create/Type/GenericType.cs index 4081075ff..b9c4e8326 100644 --- a/BHoM_Engine/Create/Type/GenericType.cs +++ b/BHoM_Engine/Create/Type/GenericType.cs @@ -142,7 +142,11 @@ private static Type GenericTypeAngleBrackets(string name, bool silent = false, b } //Main type definition as string up until the first split char (first '<'). //Number of generic arguments will be 1 less than the number of argsSplit count - return GenericType(name.Substring(0, argsSplit[0]) + "`" + (argsSplit.Count - 1), arguments, silent, takeFirstIfMultiple); + Type type = GenericType(name.Substring(0, argsSplit[0]) + "`" + (argsSplit.Count - 1), arguments, silent, takeFirstIfMultiple); + + if (type != null && name.Contains("&")) + type = type.MakeByRefType(); + return type; } /***************************************************/ @@ -209,9 +213,12 @@ private static Type GenericTypeSquareBrackets(string name, bool silent = false, arguments.Add(name.Substring(argsStarts[i], argsEnd[i] - argsStarts[i]).Trim()); } string mainName = name.Substring(0, nameEnd); - //Main type definition as string up until the first split char (first '<'). + //Main type definition as string up until the first split char (first '[['). //Number of generic arguments will be 1 less than the number of argsSplit count - return GenericType(mainName, arguments, silent, takeFirstIfMultiple); + Type type = GenericType(mainName, arguments, silent, takeFirstIfMultiple); + if (type != null && name.Contains("&")) + type = type.MakeByRefType(); + return type; } /***************************************************/ From 57e258d57e5cf182bc2a95efa5d56a354aee8643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Thu, 3 Apr 2025 10:47:01 +0100 Subject: [PATCH 4/5] Add a check if type is system type and if so, simply try to create it before running into the rest of all the checks --- BHoM_Engine/Create/Type/Type.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BHoM_Engine/Create/Type/Type.cs b/BHoM_Engine/Create/Type/Type.cs index 284a3b3d7..d33760933 100644 --- a/BHoM_Engine/Create/Type/Type.cs +++ b/BHoM_Engine/Create/Type/Type.cs @@ -49,6 +49,13 @@ public static Type Type(string name, bool silent = false, bool takeFirstIfMultip return null; } + if (name.StartsWith("System.")) //If a system type, try create it before doing anything else. If failing, rest of method will handle unqualified, generics, reference etc + { + Type type = System.Type.GetType(name); + if (type != null) + return type; + } + if (name.Contains('<')) return GenericTypeAngleBrackets(name, silent, takeFirstIfMultiple); else if (name.Contains('`') && name.Contains("[[")) From 0871b84491e9cf84e182199e301bf0fa75b43b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Thu, 3 Apr 2025 10:49:21 +0100 Subject: [PATCH 5/5] Add three more types to the explicit system types proved to be problematic in terms of deserialisation --- BHoM_Engine/Create/Type/Type.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BHoM_Engine/Create/Type/Type.cs b/BHoM_Engine/Create/Type/Type.cs index d33760933..0e94db271 100644 --- a/BHoM_Engine/Create/Type/Type.cs +++ b/BHoM_Engine/Create/Type/Type.cs @@ -110,7 +110,10 @@ public static Type Type(string name, bool silent = false, bool takeFirstIfMultip ["System.Drawing.Bitmap"] = typeof(System.Drawing.Bitmap), ["System.Collections.Generic.SortedDictionary`2"] = typeof(System.Collections.Generic.SortedDictionary<,>), ["System.Data.DataTable"] = typeof(System.Data.DataTable), - ["System.Collections.Generic.HashSet`1"] = typeof(System.Collections.Generic.HashSet<>) + ["System.Collections.Generic.HashSet`1"] = typeof(System.Collections.Generic.HashSet<>), + ["System.Xml.XmlNode"] = typeof(System.Xml.XmlNode), + ["System.Xml.Linq.XDocument"] = typeof(System.Xml.Linq.XDocument), + ["System.Collections.Concurrent.ConcurrentBag`1"] = typeof(System.Collections.Concurrent.ConcurrentBag<>) }; /*******************************************/