diff --git a/StabilityMatrix.Avalonia/Models/Inference/FileNameFormatPart.cs b/StabilityMatrix.Avalonia/Models/Inference/FileNameFormatPart.cs index 9210adc0..3b17284b 100644 --- a/StabilityMatrix.Avalonia/Models/Inference/FileNameFormatPart.cs +++ b/StabilityMatrix.Avalonia/Models/Inference/FileNameFormatPart.cs @@ -1,16 +1,7 @@ using System; -using System.Runtime.InteropServices; -using CSharpDiscriminatedUnion.Attributes; +using OneOf; namespace StabilityMatrix.Avalonia.Models.Inference; -[GenerateDiscriminatedUnion(CaseFactoryPrefix = "From")] -[StructLayout(LayoutKind.Auto)] -public readonly partial struct FileNameFormatPart -{ - [StructCase("Constant", isDefaultValue: true)] - private readonly string constant; - - [StructCase("Substitution")] - private readonly Func substitution; -} +[GenerateOneOf] +public partial class FileNameFormatPart : OneOfBase> { } diff --git a/StabilityMatrix.Avalonia/Models/Inference/FileNameFormatProvider.cs b/StabilityMatrix.Avalonia/Models/Inference/FileNameFormatProvider.cs index e8c13f79..1c5790d9 100644 --- a/StabilityMatrix.Avalonia/Models/Inference/FileNameFormatProvider.cs +++ b/StabilityMatrix.Avalonia/Models/Inference/FileNameFormatProvider.cs @@ -84,7 +84,7 @@ public partial class FileNameFormatProvider if (result.Index != currentIndex) { var constant = template[currentIndex..result.Index]; - parts.Add(FileNameFormatPart.FromConstant(constant)); + parts.Add(constant); currentIndex += constant.Length; } @@ -97,30 +97,32 @@ public partial class FileNameFormatProvider if (slice is not null) { parts.Add( - FileNameFormatPart.FromSubstitution(() => - { - var value = substitution(); - if (value is null) - return null; - - if (slice.End is null) - { - value = value[(slice.Start ?? 0)..]; - } - else + (FileNameFormatPart)( + () => { - var length = - Math.Min(value.Length, slice.End.Value) - (slice.Start ?? 0); - value = value.Substring(slice.Start ?? 0, length); + var value = substitution(); + if (value is null) + return null; + + if (slice.End is null) + { + value = value[(slice.Start ?? 0)..]; + } + else + { + var length = + Math.Min(value.Length, slice.End.Value) - (slice.Start ?? 0); + value = value.Substring(slice.Start ?? 0, length); + } + + return value; } - - return value; - }) + ) ); } else { - parts.Add(FileNameFormatPart.FromSubstitution(substitution)); + parts.Add(substitution); } currentIndex += result.Length; @@ -130,7 +132,7 @@ public partial class FileNameFormatProvider if (currentIndex != template.Length) { var constant = template[currentIndex..]; - parts.Add(FileNameFormatPart.FromConstant(constant)); + parts.Add(constant); } return parts; diff --git a/StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj b/StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj index dcc6b0ae..68eb7e14 100644 --- a/StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj +++ b/StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj @@ -32,7 +32,6 @@ -