1using Newtonsoft.Json.Linq;
7internal sealed class DefinitionProvenance
9 internal string? FilePath {
get; }
10 internal string? AssetsFilePath {
get; }
11 internal string? AssetEntryName {
get; }
12 private readonly JToken _baseline;
14 private DefinitionProvenance(
string? filePath,
string? assetsFilePath,
string? entryName,
object definition)
16 FilePath =
string.IsNullOrWhiteSpace(filePath) ? null : Path.GetFullPath(filePath);
17 AssetsFilePath =
string.IsNullOrWhiteSpace(assetsFilePath) ? null : Path.GetFullPath(assetsFilePath);
18 AssetEntryName = entryName;
19 _baseline = JToken.FromObject(definition);
22 internal static DefinitionProvenance? Capture(
string? filePath,
string? assetsFilePath,
23 string? entryName, Func<object> capture)
25 if (
string.IsNullOrWhiteSpace(filePath) &&
26 (
string.IsNullOrWhiteSpace(assetsFilePath) ||
string.IsNullOrWhiteSpace(entryName)))
28 return new(filePath, assetsFilePath, entryName, capture());
31 internal bool Matches(
object definition) => JToken.DeepEquals(_baseline, JToken.FromObject(definition));
36internal sealed class DefinitionLoadStamp
38 private readonly JToken _definition;
39 private readonly
string? _filePath;
40 private readonly
string? _assetsFilePath;
41 private readonly
string? _entryName;
43 internal DefinitionLoadStamp(
object definition,
string? filePath =
null,
string? assetsFilePath =
null,
string? entryName =
null)
45 _definition = JToken.FromObject(definition);
46 _filePath =
string.IsNullOrWhiteSpace(filePath) ? null : Path.GetFullPath(filePath);
47 _assetsFilePath =
string.IsNullOrWhiteSpace(assetsFilePath) ? null : Path.GetFullPath(assetsFilePath);
48 _entryName = entryName;
51 internal DefinitionProvenance? Materialized(
object definition, Func<object> capture) =>
52 JToken.DeepEquals(_definition, JToken.FromObject(definition))
53 ? DefinitionProvenance.Capture(_filePath, _assetsFilePath, _entryName, capture)