Struct Tckn
- Namespace
- HeroKit.Globalization.Turkey
- Assembly
- HeroKit.dll
A Turkish identity number (T.C. Kimlik Numarası) that has passed the checksum check. Validate once at the edge, then pass the value around.
[JsonConverter(typeof(TcknJsonConverter))]
[TypeConverter(typeof(TcknTypeConverter))]
public readonly struct Tckn : IEquatable<Tckn>, IComparable<Tckn>, IParsable<Tckn>
- Implements
- Inherited Members
- Extension Methods
Examples
Tckn id = Tckn.Parse("10000000146");
id.Value; // "10000000146"
id.ToMaskedString(); // "10*******46"
app.MapGet("/people/{id}", (Tckn id) => ...); // invalid numbers return 400
Remarks
Create values with Parse(string) or TryParse(string?, out Tckn). The type implements IParsable<TSelf>, so ASP.NET Core minimal APIs bind it from route and query values, and it has a JSON converter and a type converter for MVC model binding and configuration.
default(Tckn) holds no number: IsEmpty is true and Value is an empty string.
Properties
IsEmpty
Gets whether this is default(Tckn), which holds no number.
public bool IsEmpty { get; }
Property Value
Value
Gets the 11 digits, or an empty string for default(Tckn).
public string Value { get; }
Property Value
Methods
CompareTo(Tckn)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(Tckn other)
Parameters
otherTcknAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
Equals(Tckn)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Tckn other)
Parameters
otherTcknAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Parse(string)
Converts a string to a Tckn.
public static Tckn Parse(string value)
Parameters
valuestring11 digits with a valid checksum.
Returns
- Tckn
The identity number.
Exceptions
- ArgumentNullException
valueis null.- FormatException
valueis not a valid TCKN.
ToMaskedString()
Returns the number with the middle digits hidden, for logs and screens: "10*******46".
public string ToMaskedString()
Returns
- string
The masked number, or an empty string for
default(Tckn).
ToString()
Returns the 11 digits.
public override string ToString()
Returns
TryParse(string?, out Tckn)
Tries to convert a string to a Tckn.
public static bool TryParse(string? value, out Tckn result)
Parameters
valuestring11 digits with a valid checksum.
resultTcknThe identity number when the method returns true; otherwise
default.
Returns
- bool
True if the value is a valid TCKN.
Operators
operator ==(Tckn, Tckn)
Compares two identity numbers for equality.
public static bool operator ==(Tckn left, Tckn right)
Parameters
Returns
- bool
True if both hold the same number.
explicit operator Tckn(string)
Converts a string with Parse(string).
public static explicit operator Tckn(string value)
Parameters
valuestring11 digits with a valid checksum.
Returns
Exceptions
- FormatException
valueis not a valid TCKN.
implicit operator string(Tckn)
Returns the 11 digits.
public static implicit operator string(Tckn value)
Parameters
valueTcknThe identity number.
Returns
operator !=(Tckn, Tckn)
Compares two identity numbers for inequality.
public static bool operator !=(Tckn left, Tckn right)
Parameters
Returns
- bool
True if the numbers differ.