Files

48 lines
1.4 KiB
C#
Raw Permalink Normal View History

2026-03-12 09:22:03 +08:00
using System.Text.Json.Serialization;
2026-08-11 23:03:55 +08:00
namespace LanMountainDesktop.AirAppSdk;
2026-03-12 09:22:03 +08:00
2026-08-11 23:03:55 +08:00
public sealed record AirAppSharedContractReference(
2026-03-12 09:22:03 +08:00
string Id,
string Version,
string AssemblyName)
{
[JsonIgnore]
public string NormalizedId => Id.Trim();
[JsonIgnore]
public string NormalizedVersion => Version.Trim();
[JsonIgnore]
public string NormalizedAssemblyName => AssemblyName.Trim();
2026-08-11 23:03:55 +08:00
internal AirAppSharedContractReference NormalizeAndValidate(string manifestPath)
2026-03-12 09:22:03 +08:00
{
var normalized = this with
{
Id = RequireValue(Id, nameof(Id), manifestPath),
Version = RequireValue(Version, nameof(Version), manifestPath),
AssemblyName = RequireValue(AssemblyName, nameof(AssemblyName), manifestPath)
};
if (!System.Version.TryParse(normalized.Version, out _))
{
throw new InvalidOperationException(
2026-08-11 23:03:55 +08:00
$"AirApp manifest '{manifestPath}' declares invalid shared contract version '{normalized.Version}' for '{normalized.Id}'.");
2026-03-12 09:22:03 +08:00
}
return normalized;
}
private static string RequireValue(string? value, string propertyName, string manifestPath)
{
if (string.IsNullOrWhiteSpace(value))
{
throw new InvalidOperationException(
2026-08-11 23:03:55 +08:00
$"AirApp manifest '{manifestPath}' is missing required shared contract property '{propertyName}'.");
2026-03-12 09:22:03 +08:00
}
return value.Trim();
}
}