1
0
Fork 0
Questionable/Questionable.Model/Questing/ExcelRef.cs

69 lines
1.4 KiB
C#
Raw Permalink Normal View History

2024-06-12 16:03:48 +00:00
using System;
2024-08-02 16:30:21 +00:00
namespace Questionable.Model.Questing;
2024-06-12 16:03:48 +00:00
public class ExcelRef
{
private readonly string? _stringValue;
private readonly uint? _rowIdValue;
public ExcelRef(string value)
{
_stringValue = value;
_rowIdValue = null;
Type = EType.Key;
}
public ExcelRef(uint value)
{
_stringValue = null;
_rowIdValue = value;
Type = EType.RowId;
}
2024-07-16 08:54:47 +00:00
private ExcelRef(string? stringValue, uint? rowIdValue, EType type)
{
2024-07-16 08:54:47 +00:00
_stringValue = stringValue;
_rowIdValue = rowIdValue;
Type = type;
}
2024-07-16 08:54:47 +00:00
public static ExcelRef FromKey(string value) => new(value, null, EType.Key);
public static ExcelRef FromRowId(uint rowId) => new(null, rowId, EType.RowId);
public static ExcelRef FromSheetValue(string value) => new(value, null, EType.RawString);
2024-06-12 16:03:48 +00:00
public EType Type { get; }
public string AsKey()
{
if (Type != EType.Key)
throw new InvalidOperationException();
return _stringValue!;
}
public uint AsRowId()
{
if (Type != EType.RowId)
throw new InvalidOperationException();
return _rowIdValue!.Value;
}
public string AsRawString()
{
if (Type != EType.RawString)
throw new InvalidOperationException();
return _stringValue!;
}
2024-06-12 16:03:48 +00:00
public enum EType
{
None,
Key,
RowId,
RawString,
2024-06-12 16:03:48 +00:00
}
}