-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bumped CSV version and fixed Topology conversion exception
- Loading branch information
Showing
6 changed files
with
75 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="TopologyEnumConverter.cs" company="QutEcoacoustics"> | ||
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group). | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace Acoustics.Shared.Csv | ||
{ | ||
using System; | ||
using CsvHelper; | ||
using CsvHelper.Configuration; | ||
using CsvHelper.TypeConversion; | ||
|
||
public class TopologyEnumConverter : DefaultTypeConverter | ||
{ | ||
public override object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData) | ||
{ | ||
if (Enum.TryParse<Topology>(text, ignoreCase: true, out var value)) | ||
{ | ||
return value; | ||
} | ||
else | ||
{ | ||
return base.ConvertFromString(text, row, memberMapData); | ||
} | ||
} | ||
|
||
public override string ConvertToString(object value, IWriterRow row, MemberMapData memberMapData) | ||
{ | ||
return value switch | ||
{ | ||
Topology.Open => nameof(Topology.Exclusive), | ||
Topology.LeftClosedRightOpen => nameof(Topology.MinimumInclusiveMaximumExclusive), | ||
Topology.LeftOpenRightClosed => nameof(Topology.MinimumExclusiveMaximumInclusive), | ||
Topology.Closed => nameof(Topology.Inclusive), | ||
_ => throw new ArgumentException($"`{value}` is not a valid Interval Topology"), | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters