From 5b6acefec603046633079b5afb856eeec4eb505f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Tue, 1 Apr 2025 11:28:10 +0100 Subject: [PATCH 1/7] 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 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Serialiser_Engine/Compute/Deserialise/Type.cs b/Serialiser_Engine/Compute/Deserialise/Type.cs index 08d5af3bb..e041a72c8 100644 --- a/Serialiser_Engine/Compute/Deserialise/Type.cs +++ b/Serialiser_Engine/Compute/Deserialise/Type.cs @@ -146,17 +146,14 @@ 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 = type = Base.Create.Type(fullName, true, true); } + if (type == null) { List types = Base.Create.AllTypes(fullName, true); @@ -167,8 +164,8 @@ private static Type GetTypeFromName(string fullName) return type; } - /*******************************************/ + /*******************************************/ } } From af4d19c79bc451dc63c57e0235d6baec93c9bcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Tue, 1 Apr 2025 11:29:37 +0100 Subject: [PATCH 2/7] 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 b88adf5caca585bb16371e8f077d720e2e8a6625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Tue, 1 Apr 2025 11:30:29 +0100 Subject: [PATCH 3/7] Handle ref type for generic type creation --- BHoM_Engine/Create/Type/GenericType.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/BHoM_Engine/Create/Type/GenericType.cs b/BHoM_Engine/Create/Type/GenericType.cs index 4081075ff..bf3f8e4c2 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; } /***************************************************/ @@ -211,7 +215,10 @@ private static Type GenericTypeSquareBrackets(string name, bool silent = false, string mainName = name.Substring(0, nameEnd); //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 947033eb390f2ea78321ce4e1eaf27864bfa47aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Tue, 1 Apr 2025 11:31:34 +0100 Subject: [PATCH 4/7] 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 d731183ce158e44e675aeae3ff2645dedd8c6938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Tue, 1 Apr 2025 11:32:22 +0100 Subject: [PATCH 5/7] Add two more missing ExplicitSystemTypes shown to be failing --- BHoM_Engine/Create/Type/Type.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BHoM_Engine/Create/Type/Type.cs b/BHoM_Engine/Create/Type/Type.cs index d33760933..6235a2136 100644 --- a/BHoM_Engine/Create/Type/Type.cs +++ b/BHoM_Engine/Create/Type/Type.cs @@ -110,7 +110,9 @@ 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), }; /*******************************************/ From 1e8a1ed47cffaf1a89836664ceca47d86fcf11e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Tue, 1 Apr 2025 11:40:45 +0100 Subject: [PATCH 6/7] Remove blank line --- Serialiser_Engine/Compute/Deserialise/Type.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Serialiser_Engine/Compute/Deserialise/Type.cs b/Serialiser_Engine/Compute/Deserialise/Type.cs index e041a72c8..d9475a8e0 100644 --- a/Serialiser_Engine/Compute/Deserialise/Type.cs +++ b/Serialiser_Engine/Compute/Deserialise/Type.cs @@ -164,7 +164,6 @@ private static Type GetTypeFromName(string fullName) return type; } - /*******************************************/ } } From af38e149471d52d24cded55c91970d684ad6a7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Tue, 1 Apr 2025 11:41:15 +0100 Subject: [PATCH 7/7] One more blank line --- Serialiser_Engine/Compute/Deserialise/Type.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Serialiser_Engine/Compute/Deserialise/Type.cs b/Serialiser_Engine/Compute/Deserialise/Type.cs index d9475a8e0..8dcafdf6f 100644 --- a/Serialiser_Engine/Compute/Deserialise/Type.cs +++ b/Serialiser_Engine/Compute/Deserialise/Type.cs @@ -153,7 +153,6 @@ private static Type GetTypeFromName(string fullName) type = type = Base.Create.Type(fullName, true, true); } - if (type == null) { List types = Base.Create.AllTypes(fullName, true);