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; } /***************************************************/ diff --git a/BHoM_Engine/Create/Type/Type.cs b/BHoM_Engine/Create/Type/Type.cs index 6bd9c9a64..0e94db271 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("[[")) @@ -67,9 +74,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(); } @@ -103,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<>) }; /*******************************************/ 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) {