Files
git.stella-ops.org/src/__Libraries/StellaOps.Configuration/StellaOpsAuthorityOptions.Helpers.cs

52 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using static StellaOps.Localization.T;
namespace StellaOps.Configuration;
public sealed partial class StellaOpsAuthorityOptions
{
private static void ValidateLifetime(TimeSpan value, string propertyName, TimeSpan maximum)
{
if (value <= TimeSpan.Zero)
{
throw new InvalidOperationException(_t("config.authority.property_greater_than_zero", propertyName));
}
if (value > maximum)
{
throw new InvalidOperationException(_t("config.authority.property_max", propertyName, maximum));
}
}
private static void NormaliseList(IList<string> values)
{
if (values.Count == 0)
{
return;
}
var unique = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
for (var index = values.Count - 1; index >= 0; index--)
{
var entry = values[index];
if (string.IsNullOrWhiteSpace(entry))
{
values.RemoveAt(index);
continue;
}
var trimmed = entry.Trim();
if (!unique.Add(trimmed))
{
values.RemoveAt(index);
continue;
}
values[index] = trimmed;
}
}
}