init
This commit is contained in:
202
Common/DTS.Common/Classes/ISO/IsoCode.cs
Normal file
202
Common/DTS.Common/Classes/ISO/IsoCode.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
using System.Text;
|
||||
|
||||
namespace DTS.Common.ISO
|
||||
{
|
||||
public class IsoCode
|
||||
{
|
||||
private readonly char[] _isoCodeFull = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
|
||||
|
||||
private char _testObject
|
||||
{
|
||||
get => _isoCodeFull[0];
|
||||
set => _isoCodeFull[0] = value;
|
||||
}
|
||||
|
||||
public string TestObject
|
||||
{
|
||||
get => new string(new[] { _testObject });
|
||||
set => _testObject = string.IsNullOrEmpty(value) ? '?' : value[0];
|
||||
}
|
||||
|
||||
private char _position
|
||||
{
|
||||
get => _isoCodeFull[1];
|
||||
set => _isoCodeFull[1] = value;
|
||||
}
|
||||
|
||||
public string Position
|
||||
{
|
||||
get => new string(new[] { _position });
|
||||
set => _position = string.IsNullOrEmpty(value) ? '?' : value[0];
|
||||
}
|
||||
private char[] _mainLocation
|
||||
{
|
||||
get => new[] { _isoCodeFull[2], _isoCodeFull[3], _isoCodeFull[4], _isoCodeFull[5] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
if (value.Length <= i) { _isoCodeFull[i + 2] = '0'; }
|
||||
else { _isoCodeFull[i + 2] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MainLocation
|
||||
{
|
||||
get => new string(_mainLocation);
|
||||
set
|
||||
{
|
||||
var main = value;
|
||||
if (main.Length < 4) { main = main.PadRight(4, '?'); }
|
||||
else if (main.Length > 4) { main = main.Substring(0, 4); }
|
||||
_mainLocation = main.ToCharArray(0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
private char[] _fineLocation1
|
||||
{
|
||||
get => new[] { _isoCodeFull[6], _isoCodeFull[7] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
_isoCodeFull[i + 6] = value.Length < i ? '0' : value[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
public string FineLocation1
|
||||
{
|
||||
get => new string(_fineLocation1);
|
||||
set
|
||||
{
|
||||
var loc = value;
|
||||
if (loc.Length < 2) { loc = loc.PadRight(2, '?'); }
|
||||
_fineLocation1 = loc.ToCharArray(0, 2);
|
||||
}
|
||||
}
|
||||
private char[] _fineLocation2
|
||||
{
|
||||
get => new[] { _isoCodeFull[8], _isoCodeFull[9] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i) { _isoCodeFull[i + 8] = '0'; }
|
||||
else { _isoCodeFull[i + 8] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
public string FineLocation2
|
||||
{
|
||||
get => new string(_fineLocation2);
|
||||
set
|
||||
{
|
||||
var loc = value;
|
||||
if (loc.Length < 2) { loc = loc.PadRight(2, '?'); }
|
||||
_fineLocation2 = loc.ToCharArray(0, 2);
|
||||
}
|
||||
}
|
||||
private char[] _fineLocation3
|
||||
{
|
||||
get => new[] { _isoCodeFull[10], _isoCodeFull[11] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i) { _isoCodeFull[i + 10] = '0'; }
|
||||
else { _isoCodeFull[i + 10] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
public string FineLocation3
|
||||
{
|
||||
get => new string(_fineLocation3);
|
||||
set
|
||||
{
|
||||
var loc = value;
|
||||
if (loc.Length < 2) { loc = loc.PadRight(2, '?'); }
|
||||
_fineLocation3 = loc.ToCharArray(0, 2);
|
||||
}
|
||||
}
|
||||
private char[] _physicalDimension
|
||||
{
|
||||
get => new[] { _isoCodeFull[12], _isoCodeFull[13] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i) { _isoCodeFull[i + 12] = '0'; }
|
||||
else { _isoCodeFull[i + 12] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
public string PhysicalDimension
|
||||
{
|
||||
get => new string(_physicalDimension);
|
||||
set
|
||||
{
|
||||
var dim = value;
|
||||
if (dim.Length < 2) { dim = dim.PadRight(2, '?'); }
|
||||
else if (dim.Length > 2) { dim = dim.Substring(0, 2); }
|
||||
_physicalDimension = dim.ToCharArray(0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private char _direction
|
||||
{
|
||||
get => _isoCodeFull[14];
|
||||
set => _isoCodeFull[14] = value;
|
||||
}
|
||||
|
||||
public string Direction
|
||||
{
|
||||
get => new string(new[] { _direction });
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) { _direction = '?'; }
|
||||
else { _direction = value[0]; }
|
||||
}
|
||||
}
|
||||
|
||||
private char _filterClass
|
||||
{
|
||||
get => _isoCodeFull[15];
|
||||
set => _isoCodeFull[15] = value;
|
||||
}
|
||||
|
||||
public string FilterClass
|
||||
{
|
||||
get => new string(new[] { _filterClass });
|
||||
set => _filterClass = string.IsNullOrEmpty(value) ? '?' : value[0];
|
||||
}
|
||||
|
||||
public IsoCode(string isoCode)
|
||||
{
|
||||
if (null == isoCode) { isoCode = ""; }
|
||||
if (isoCode.Length > 16) { isoCode = isoCode.Substring(0, 16); }
|
||||
if (isoCode.Length < 16)
|
||||
{
|
||||
isoCode = isoCode.PadRight(16, '?');
|
||||
}
|
||||
for (var i = 0; i < 16; i++) { _isoCodeFull[i] = isoCode[i]; }
|
||||
}
|
||||
public string StringRepresentation
|
||||
{
|
||||
get
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var c in _isoCodeFull) { sb.Append(c); }
|
||||
return sb.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 16; i++)
|
||||
{
|
||||
if (i >= value.Length) { _isoCodeFull[i] = '0'; }
|
||||
else { _isoCodeFull[i] = value[i]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user