Browse Source

Change from DiscriminatedUnion to OneOf

pull/240/head
Ionite 1 year ago
parent
commit
c9d50071ed
No known key found for this signature in database
  1. 15
      StabilityMatrix.Avalonia/Models/Inference/FileNameFormatPart.cs
  2. 12
      StabilityMatrix.Avalonia/Models/Inference/FileNameFormatProvider.cs
  3. 1
      StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj

15
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<string?> substitution;
}
[GenerateOneOf]
public partial class FileNameFormatPart : OneOfBase<string, Func<string?>> { }

12
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,7 +97,8 @@ public partial class FileNameFormatProvider
if (slice is not null)
{
parts.Add(
FileNameFormatPart.FromSubstitution(() =>
(FileNameFormatPart)(
() =>
{
var value = substitution();
if (value is null)
@ -115,12 +116,13 @@ public partial class FileNameFormatProvider
}
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;

1
StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj

@ -32,7 +32,6 @@
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.2" />
<PackageReference Include="AvaloniaEdit.TextMate" Version="11.0.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="CSharpDiscriminatedUnion" Version="2.0.1" />
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageReference Include="Dock.Avalonia" Version="11.0.0.2" />
<PackageReference Include="Dock.Model.Avalonia" Version="11.0.0.2" />

Loading…
Cancel
Save