1using Newtonsoft.Json.Linq;
7internal sealed class DefinitionProvenance
9 internal string? FilePath {
get; }
10 internal string? AssetsFilePath {
get; }
11 internal string? AssetEntryName {
get; }
14 internal string? DefinitionIdentity {
get; }
16 private readonly JToken _baseline;
18 private DefinitionProvenance(
20 string? assetsFilePath,
23 string? definitionIdentity)
25 FilePath =
string.IsNullOrWhiteSpace(filePath) ? null : Path.GetFullPath(filePath);
26 AssetsFilePath =
string.IsNullOrWhiteSpace(assetsFilePath) ? null : Path.GetFullPath(assetsFilePath);
27 AssetEntryName = entryName;
28 DefinitionIdentity = definitionIdentity;
29 _baseline = JToken.FromObject(definition);
39 internal static DefinitionProvenance? Capture(
41 string? assetsFilePath,
44 string? definitionIdentity =
null)
46 if (
string.IsNullOrWhiteSpace(filePath) &&
47 (
string.IsNullOrWhiteSpace(assetsFilePath) ||
string.IsNullOrWhiteSpace(entryName)))
58 internal bool Matches(
object definition) => JToken.DeepEquals(_baseline, JToken.FromObject(definition));
63internal sealed class DefinitionLoadStamp
65 private readonly JToken _definition;
66 private readonly
string? _filePath;
67 private readonly
string? _assetsFilePath;
68 private readonly
string? _entryName;
69 private readonly
string? _definitionIdentity;
72 internal string? AssetsFilePath => _assetsFilePath;
75 internal string? ReferenceBaseDirectory => _filePath is not
null ? Path.GetDirectoryName(_filePath) :
76 _assetsFilePath is not
null ? Path.GetDirectoryName(_assetsFilePath) :
null;
84 internal DefinitionLoadStamp(
86 string? filePath =
null,
87 string? assetsFilePath =
null,
88 string? entryName =
null,
89 string? definitionIdentity =
null)
91 _definition = JToken.FromObject(definition);
92 _filePath =
string.IsNullOrWhiteSpace(filePath) ? null : Path.GetFullPath(filePath);
93 _assetsFilePath =
string.IsNullOrWhiteSpace(assetsFilePath) ? null : Path.GetFullPath(assetsFilePath);
94 _entryName = entryName;
95 _definitionIdentity = definitionIdentity;
98 internal DefinitionProvenance? Materialized(
object definition, Func<object> capture) =>
99 JToken.DeepEquals(_definition, JToken.FromObject(definition))
100 ? DefinitionProvenance.Capture(