From 40eca002746adcd72a6f78a5803ccadc62200de9 Mon Sep 17 00:00:00 2001 From: Seun Akanni Date: Sun, 13 Sep 2026 14:05:04 +0100 Subject: [PATCH] feat(test-engine): record the declaring assembly on captured object records Object records in the versioning test datasets record what a type is called but not where it is declared, so a consumer reading one has only a type name. Method records do not have this problem: a method's declaring type is serialised assembly-qualified. Adds an `_asm` field naming the assembly the object's type came from. One property read, one field written, on the successful records only. The field is added after the ToJson, FromJson and IsEqual checks, so those run on the record as serialised and the method's verdict is unchanged. The output tuple is unchanged. Method records are skipped. The field is placed immediately before `_bhomVersion` so it sits past the positional indices Helpers.DescriptionFromJson reads. Inert to existing readers: the deserialiser skips fields whose name begins with an underscore. --- .../TryToJsonAndFromJsonAndCheckIfEqual.cs | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Test_Engine/Compute/TryToJsonAndFromJsonAndCheckIfEqual.cs b/Test_Engine/Compute/TryToJsonAndFromJsonAndCheckIfEqual.cs index 7b6f9534..077d0507 100644 --- a/Test_Engine/Compute/TryToJsonAndFromJsonAndCheckIfEqual.cs +++ b/Test_Engine/Compute/TryToJsonAndFromJsonAndCheckIfEqual.cs @@ -114,7 +114,8 @@ public static Output, List, List, List, Lis if (isEqual) { - successfulJson.Add(json); + // Added here, after the checks, so they run on the json as serialised. + successfulJson.Add(AddDeclaringAssembly(json, obj)); successfulJsonObjects.Add(obj); } else @@ -137,6 +138,50 @@ public static Output, List, List, List, Lis Item8 = notEqualObjects }; } + + /***************************************************/ + /**** Private Methods ****/ + /***************************************************/ + + [Description("Records the assembly declaring the object's type on the record, as an `_asm` field.")] + [Input("json", "Serialised record to add the field to.")] + [Input("obj", "Object the record was serialised from.")] + [Output("json", "The record, with the declaring assembly recorded on it.")] + private static string AddDeclaringAssembly(string json, object obj) + { + if (string.IsNullOrEmpty(json) || obj == null) + return json; + + // A method record already carries its declaring assembly, because its declaring type is + // serialised assembly-qualified. Its top-level type is MethodBase, so recording the + // assembly of that would be untrue. + if (obj is System.Reflection.MethodBase) + return json; + + string assembly; + try + { + assembly = obj.GetType().Assembly.GetName().Name; + } + catch + { + // Left as it was. A guessed value would be indistinguishable from a real one. + return json; + } + + if (string.IsNullOrWhiteSpace(assembly)) + return json; + + // Before `_bhomVersion`, which Versioning_Engine appends last. Helpers.DescriptionFromJson + // reads fixed quote-delimited indices, so the field has to sit past them. + int at = json.LastIndexOf("\"_bhomVersion\"", StringComparison.Ordinal); + if (at < 0) + return json; + + return json.Substring(0, at) + $"\"_asm\" : \"{assembly}\", " + json.Substring(at); + } + + /***************************************************/ } }