45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace AutoCat.Views;
|
||
|
||
//[CreateFromString(MethodName = "AutoCat.Controls.PlateNumber.ConvertFromString")]
|
||
public class PlateNumber
|
||
{
|
||
private readonly string _number;
|
||
private readonly string _numberEnglish;
|
||
|
||
private readonly Dictionary<char, char> _lettersMap = new()
|
||
{
|
||
{ 'А', 'A' }, { 'В', 'B' }, { 'Е', 'E' }, { 'К', 'K' },
|
||
{ 'М', 'M' }, { 'Н', 'H' }, { 'О', 'O' }, { 'Р', 'P' },
|
||
{ 'С', 'C' }, { 'Т', 'T' }, { 'У', 'Y' }, { 'Х', 'X' }
|
||
};
|
||
|
||
public PlateNumber(string number)
|
||
{
|
||
this._number = number;
|
||
this._numberEnglish = string.Concat(number.Select(c => _lettersMap.TryGetValue(c, out var eng) ? eng : c));
|
||
}
|
||
|
||
public string AsString()
|
||
{
|
||
return _number;
|
||
}
|
||
|
||
public string MainPart()
|
||
{
|
||
return _numberEnglish[..6];
|
||
}
|
||
|
||
public string Region()
|
||
{
|
||
return _numberEnglish[6..];
|
||
}
|
||
|
||
public static PlateNumber ConvertFromString(string number)
|
||
{
|
||
return new PlateNumber(number);
|
||
}
|
||
} |