diff --git a/PInvoke/Shared/WinDef/LCID.cs b/PInvoke/Shared/WinDef/LCID.cs new file mode 100644 index 00000000..2497cfcc --- /dev/null +++ b/PInvoke/Shared/WinDef/LCID.cs @@ -0,0 +1,102 @@ +using System; +using System.ComponentModel; +using System.Globalization; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + /// + /// + /// + [StructLayout(LayoutKind.Sequential)] + [TypeConverter(typeof(NTStatusTypeConverter))] + public partial struct LCID : IComparable, IComparable, IEquatable + { + internal readonly uint _value; + + private const int langMask = 0x0FFFF; + private const uint sortMask = 0xF0000; + private const int sortShift = 16; + + /// Initializes a new instance of the structure. + /// The raw NTStatus value. + public LCID(uint rawValue) => _value = rawValue; + + /// Compares the current object with another object of the same type. + /// An object to compare with this object. + /// + /// A value that indicates the relative order of the objects being compared. The return value has the following + /// meanings: Value Meaning Less than zero This object is less than the parameter.Zero This object is equal + /// to . Greater than zero This object is greater than . + /// + public int CompareTo(LCID other) => _value.CompareTo(other._value); + + /// + /// 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. + /// + /// An object to compare with this instance. + /// + /// 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 in the sort order. Zero This instance occurs in the same position in the + /// sort order as . Greater than zero This instance follows in the sort order. + /// + public int CompareTo(object obj) + { + if (!(obj is IConvertible c)) throw new ArgumentException(@"Object cannot be converted to a UInt32 value for comparison.", nameof(obj)); + return _value.CompareTo(c.ToUInt32(null)); + } + + /// Determines whether the specified , is equal to this instance. + /// The to compare with this instance. + /// true if the specified is equal to this instance; otherwise, false. + public override bool Equals(object obj) => obj is IConvertible c ? _value.Equals(c.ToUInt32(null)) : false; + + /// Indicates whether the current object is equal to another object of the same type. + /// An object to compare with this object. + /// true if the current object is equal to the parameter; otherwise, false. + public bool Equals(LCID other) => other._value == _value; + + /// Returns a hash code for this instance. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + public override int GetHashCode() => _value.GetHashCode(); + + /// Returns a that represents this instance. + /// A that represents this instance. + public override string ToString() => string.Format(CultureInfo.InvariantCulture, "0x{0:X8}", _value); + + /// Implements the operator ==. + /// The first . + /// The second . + /// The result of the operator. + public static bool operator ==(LCID hrLeft, LCID hrRight) => hrLeft._value == hrRight._value; + + /// Implements the operator ==. + /// The first . + /// The second . + /// The result of the operator. + public static bool operator ==(LCID hrLeft, uint hrRight) => hrLeft._value == hrRight; + + /// Implements the operator !=. + /// The first . + /// The second . + /// The result of the operator. + public static bool operator !=(LCID hrLeft, LCID hrRight) => !(hrLeft == hrRight); + + /// Implements the operator !=. + /// The first . + /// The second . + /// The result of the operator. + public static bool operator !=(LCID hrLeft, uint hrRight) => !(hrLeft == hrRight); + + /// Performs an implicit conversion from to . + /// The value. + /// The result of the conversion. + public static implicit operator LCID(uint value) => new LCID(value); + + /// Performs an explicit conversion from to . + /// The value. + /// The result of the conversion. + public static explicit operator uint(LCID value) => value._value; + } +} \ No newline at end of file