Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

124 linhas
4.3 KiB

  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using System;
  22. using System.Diagnostics.CodeAnalysis;
  23. using System.Runtime.InteropServices;
  24. namespace Alphaleonis.Win32.Filesystem
  25. {
  26. internal static partial class NativeMethods
  27. {
  28. /// <summary>Represents the number of 100-nanosecond intervals since January 1, 1601. This structure is a 64-bit value.</summary>
  29. [SerializableAttribute]
  30. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
  31. internal struct FILETIME
  32. {
  33. #region Fields
  34. private readonly uint dwLowDateTime;
  35. private readonly uint dwHighDateTime;
  36. #endregion // Fields
  37. #region Methods
  38. /// <summary>Converts a value to long.</summary>
  39. public static implicit operator long(FILETIME ft)
  40. {
  41. return ft.ToLong();
  42. }
  43. /// <summary>Converts a value to long.</summary>
  44. [SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "long")]
  45. public long ToLong()
  46. {
  47. return NativeMethods.ToLong(dwHighDateTime, dwLowDateTime);
  48. }
  49. #endregion
  50. #region Equality
  51. #region Equals
  52. /// <summary>Determines whether the specified Object is equal to the current Object.</summary>
  53. /// <param name="obj">Another object to compare to.</param>
  54. /// <returns><see langword="true"/> if the specified Object is equal to the current Object; otherwise, <see langword="false"/>.</returns>
  55. public override bool Equals(object obj)
  56. {
  57. if (obj == null || GetType() != obj.GetType())
  58. return false;
  59. FILETIME other = obj is FILETIME ? (FILETIME)obj : new FILETIME();
  60. return (other.dwHighDateTime.Equals(dwHighDateTime) &&
  61. other.dwLowDateTime.Equals(dwLowDateTime));
  62. }
  63. #endregion // Equals
  64. #region GetHashCode
  65. /// <summary>Serves as a hash function for a particular type.</summary>
  66. /// <returns>A hash code for the current Object.</returns>
  67. public override int GetHashCode()
  68. {
  69. unchecked
  70. {
  71. int hash = 17;
  72. hash = hash * 23 + dwHighDateTime.GetHashCode();
  73. hash = hash * 11 + dwLowDateTime.GetHashCode();
  74. return hash;
  75. }
  76. }
  77. #endregion // GetHashCode
  78. #region ==
  79. /// <summary>Implements the operator ==</summary>
  80. /// <param name="left">A.</param>
  81. /// <param name="right">B.</param>
  82. /// <returns>The result of the operator.</returns>
  83. public static bool operator ==(FILETIME left, FILETIME right)
  84. {
  85. return left.Equals(right);
  86. }
  87. #endregion // ==
  88. #region !=
  89. /// <summary>Implements the operator !=</summary>
  90. /// <param name="left">A.</param>
  91. /// <param name="right">B.</param>
  92. /// <returns>The result of the operator.</returns>
  93. public static bool operator !=(FILETIME left, FILETIME right)
  94. {
  95. return !(left == right);
  96. }
  97. #endregion // !=
  98. #endregion // Equality
  99. }
  100. }
  101. }