Skip to content

Commit

Permalink
Use primary constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBoxyBear committed Jan 4, 2024
1 parent f71cf92 commit 51b8be8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
4 changes: 1 addition & 3 deletions ChartTools/Chords/Phrase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ChartTools.Lyrics;

public class Phrase : TrackObjectBase, IChord, ILongTrackObject
public class Phrase(uint position) : TrackObjectBase(position), IChord, ILongTrackObject
{
public List<Syllable> Syllables { get; } = [];
IReadOnlyCollection<INote> IChord.Notes => Syllables;
Expand Down Expand Up @@ -55,8 +55,6 @@ public uint? LengthOverride
public string RawText => BuildText(n => n.RawText);
public string DisplayedText => BuildText(n => n.DisplayedText);

public Phrase(uint position) : base(position) { }

public IEnumerable<GlobalEvent> ToGlobalEvents()
{
yield return new(Position, EventTypeHelper.Global.PhraseStart);
Expand Down
16 changes: 6 additions & 10 deletions ChartTools/IO/FileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace ChartTools.IO;

internal abstract class FileReader<T> : IDisposable
internal abstract class FileReader<T>(string path) : IDisposable
{
public string Path { get; }
public string Path { get; } = path;
public bool IsReading { get; protected set; }
public abstract IEnumerable<FileParser<T>> Parsers { get; }

public FileReader(string path) => Path = path;

public abstract void Read();
public abstract Task ReadAsync(CancellationToken cancellationToken);

Expand All @@ -22,17 +20,15 @@ protected void CheckBusy()
public abstract void Dispose();
}

internal abstract class FileReader<T, TParser> : FileReader<T> where TParser : FileParser<T>
internal abstract class FileReader<T, TParser>(string path, Func<string, TParser?> parserGetter) : FileReader<T>(path) where TParser : FileParser<T>
{
public record ParserContentGroup(TParser Parser, DelayedEnumerableSource<T> Source);

public override IEnumerable<TParser> Parsers => parserGroups.Select(g => g.Parser);

protected readonly List<ParserContentGroup> parserGroups = new();
protected readonly List<Task> parseTasks = new();
protected readonly Func<string, TParser?> parserGetter;

public FileReader(string path, Func<string, TParser?> parserGetter) : base(path) => this.parserGetter = parserGetter;
protected readonly List<ParserContentGroup> parserGroups = [];
protected readonly List<Task> parseTasks = [];
protected readonly Func<string, TParser?> parserGetter = parserGetter;

public override void Read()
{
Expand Down
5 changes: 2 additions & 3 deletions ChartTools/IO/Ini/IniFileWriter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace ChartTools.IO.Ini;

internal class IniFileWriter : TextFileWriter
internal class IniFileWriter(string path, params Serializer<string>[] serializers)
: TextFileWriter(path, Enumerable.Empty<string>(), serializers)
{
public IniFileWriter(string path, params Serializer<string>[] serializers) : base(path, Enumerable.Empty<string>(), serializers) { }

protected override bool EndReplace(string line) => line.StartsWith('[');
}

0 comments on commit 51b8be8

Please sign in to comment.