From fd61be41477f8b32c29e5f7a2d44b8476fc7e62f Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 28 Mar 2022 17:40:59 +0100 Subject: [PATCH] simplify uuid FromDB a bit. Note only 32 or 36 chars formats accepted if string. File is wrongly named DCGuids, since it is only about UUID --- OpenSim/Data/DBGuids.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/OpenSim/Data/DBGuids.cs b/OpenSim/Data/DBGuids.cs index ed0e7ca4e1..e2ca798dad 100644 --- a/OpenSim/Data/DBGuids.cs +++ b/OpenSim/Data/DBGuids.cs @@ -49,23 +49,21 @@ namespace OpenSim.Data Type idtype = id.GetType(); + if (idtype == typeof(string)) + { + UUID.TryParse((string)id, out UUID result); + return result; + } + if (idtype == typeof(Guid)) return new UUID((Guid)id); - if (id.GetType() == typeof(string)) - { - Guid gg; - if (Guid.TryParse((string)id, out gg)) - return new UUID(gg); - return UUID.Zero; - } - if (idtype == typeof(byte[])) { - if (((byte[])id).Length < 16) - return UUID.Zero; - return new UUID((byte[])id, 0); + byte[] idb = (byte[])id; + return idb.Length < 16 ? UUID.Zero : new UUID(idb, 0); } + throw new Exception("Failed to convert db value to UUID: " + id.ToString()); } }