2024-06-12 16:03:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Questionable.Model.V1;
|
|
|
|
|
|
|
|
|
|
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-14 21:26:06 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Only used internally (not serialized) with specific values that have been read from the sheets already.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private ExcelRef(string value, bool v)
|
|
|
|
|
{
|
|
|
|
|
if (!v)
|
|
|
|
|
throw new ArgumentException(nameof(v));
|
|
|
|
|
|
|
|
|
|
_stringValue = value;
|
|
|
|
|
_rowIdValue = null;
|
|
|
|
|
Type = EType.RawString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ExcelRef FromSheetValue(string value) => new(value, true);
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-14 21:26:06 +00:00
|
|
|
|
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,
|
2024-07-14 21:26:06 +00:00
|
|
|
|
RawString,
|
2024-06-12 16:03:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|