Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.26 KB | None | 0 0
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 06-January-2016
  4. ' ***********************************************************************
  5.  
  6. #Region " Public Members Summary "
  7.  
  8. #Region " Constructors "
  9.  
  10. ' New()
  11.  
  12. #End Region
  13.  
  14. #Region " Functions "
  15.  
  16. ' Compare(Object, Object) As Integer : Implements IComparer.Compare
  17.  
  18. #End Region
  19.  
  20. #End Region
  21.  
  22. #Region " Option Statements "
  23.  
  24. Option Strict On
  25. Option Explicit On
  26. Option Infer Off
  27.  
  28. #End Region
  29.  
  30. #Region " Imports "
  31.  
  32. Imports System
  33. Imports System.Collections
  34. Imports System.ComponentModel
  35. Imports System.Diagnostics
  36. Imports System.Linq
  37.  
  38. Imports Elektro.Application.UI.Enums
  39.  
  40. #End Region
  41.  
  42. #Region " Numeric Comparer "
  43.  
  44. Namespace Types
  45.  
  46.     ''' ----------------------------------------------------------------------------------------------------
  47.     ''' <summary>
  48.     ''' Performs a comparison between two numeric values.
  49.     ''' </summary>
  50.     ''' ----------------------------------------------------------------------------------------------------
  51.     Public NotInheritable Class NumericComparer : Implements IComparer
  52.  
  53. #Region " Constructors "
  54.  
  55.         ''' ----------------------------------------------------------------------------------------------------
  56.         ''' <summary>
  57.         ''' Initializes a new instance of the <see cref="NumericComparer"/> class.
  58.         ''' </summary>
  59.         ''' ----------------------------------------------------------------------------------------------------
  60.         <DebuggerNonUserCode>
  61.         Public Sub New()
  62.         End Sub
  63.  
  64. #End Region
  65.  
  66. #Region " Public Methods "
  67.  
  68.         ''' ----------------------------------------------------------------------------------------------------
  69.         ''' <summary>
  70.         ''' Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
  71.         ''' </summary>
  72.         ''' ----------------------------------------------------------------------------------------------------
  73.         ''' <param name="a">
  74.         ''' The first object to compare.
  75.         ''' </param>
  76.         '''
  77.         ''' <param name="b">
  78.         ''' The second object to compare.
  79.         ''' </param>
  80.         ''' ----------------------------------------------------------------------------------------------------
  81.         ''' <returns>
  82.         ''' A signed integer that indicates the relative values of <paramref name="a"/> and <paramref name="b"/>.
  83.         ''' <para></para>
  84.         ''' 0: <paramref name="a"/> equals <paramref name="b"/>.
  85.         ''' <para></para>
  86.         ''' Less than 0: <paramref name="a" /> is less than <paramref name="b"/>.
  87.         ''' <para></para>
  88.         ''' Greater than 0: <paramref name="a"/> is greater than <paramref name="b"/>.
  89.         ''' </returns>
  90.         ''' ----------------------------------------------------------------------------------------------------
  91.         <DebuggerStepThrough>
  92.         Public Function Compare(ByVal a As Object, ByVal b As Object) As Integer Implements IComparer.Compare
  93.  
  94.             ' Null parsing.
  95.             If a Is Nothing AndAlso b Is Nothing Then
  96.                 Return ComparerResult.Equals ' A is equals to B.
  97.  
  98.             ElseIf a Is Nothing AndAlso b IsNot Nothing Then
  99.                 Return ComparerResult.LessThan ' A is less than B.
  100.  
  101.             ElseIf a IsNot Nothing AndAlso b Is Nothing Then
  102.                 Return ComparerResult.GreaterThan ' A is greater than B.
  103.  
  104.             Else
  105.                 Dim singleA As Single
  106.                 Dim singleB As Single
  107.  
  108.                 If Single.TryParse(CStr(a), singleA) AndAlso Single.TryParse(CStr(b), singleB) Then ' True And True.
  109.                     Return DirectCast(singleA.CompareTo(singleB), ComparerResult)
  110.  
  111.                 ElseIf Single.TryParse(CStr(a), singleA) AndAlso Not Single.TryParse(CStr(b), singleB) Then ' True And False.
  112.                     Return ComparerResult.GreaterThan ' A is greater than B.
  113.  
  114.                 ElseIf Not Single.TryParse(CStr(a), singleA) AndAlso Single.TryParse(CStr(b), singleB) Then ' False And True.
  115.                     Return ComparerResult.LessThan ' A is less than B.
  116.  
  117.                 Else ' False And False.
  118.                     Return DirectCast(a.ToString.CompareTo(b.ToString), ComparerResult)
  119.  
  120.                 End If
  121.  
  122.             End If
  123.  
  124.         End Function
  125.  
  126. #End Region
  127.  
  128. #Region " Hidden Base Members "
  129.  
  130.         ''' ----------------------------------------------------------------------------------------------------
  131.         ''' <summary>
  132.         ''' Determines whether the specified <see cref="Object"/> is equal to this instance.
  133.         ''' </summary>
  134.         ''' ----------------------------------------------------------------------------------------------------
  135.         ''' <param name="obj">
  136.         ''' Another object to compare to.
  137.         ''' </param>
  138.         ''' ----------------------------------------------------------------------------------------------------
  139.         ''' <returns>
  140.         ''' <see langword="True"/> if the specified <see cref="Object"/> is equal to this instance; otherwise, <see langword="False"/>.
  141.         ''' </returns>
  142.         ''' ----------------------------------------------------------------------------------------------------
  143.         <EditorBrowsable(EditorBrowsableState.Never)>
  144.         <DebuggerNonUserCode>
  145.         Public Shadows Function Equals(ByVal obj As Object) As Boolean
  146.             Return MyBase.Equals(obj)
  147.         End Function
  148.  
  149.         ''' ----------------------------------------------------------------------------------------------------
  150.         ''' <summary>
  151.         ''' Determines whether the specified <see cref="System.Object"/> instances are the same instance.
  152.         ''' </summary>
  153.         ''' ----------------------------------------------------------------------------------------------------
  154.         ''' <param name="objA">
  155.         ''' The first object to compare.
  156.         ''' </param>
  157.         ''' ----------------------------------------------------------------------------------------------------
  158.         ''' <param name="objB">
  159.         ''' The second object to compare.
  160.         ''' </param>
  161.         ''' ----------------------------------------------------------------------------------------------------
  162.         ''' <returns>
  163.         ''' <see langword="True"/> if <paramref name="objA"/> is the same instance as <paramref name="objB"/>
  164.         ''' or if both are <see langword="Nothing"/>; otherwise, <see langword="False"/>.
  165.         ''' </returns>
  166.         ''' ----------------------------------------------------------------------------------------------------
  167.         <EditorBrowsable(EditorBrowsableState.Never)>
  168.         <DebuggerNonUserCode>
  169.         Public Shadows Function ReferenceEquals(ByVal objA As Object, ByVal objB As Object) As Boolean
  170.             Return Object.ReferenceEquals(objA, objB)
  171.         End Function
  172.  
  173.         ''' ----------------------------------------------------------------------------------------------------
  174.         ''' <summary>
  175.         ''' Gets the <see cref="System.Type"/> of the current instance.
  176.         ''' </summary>
  177.         ''' ----------------------------------------------------------------------------------------------------
  178.         ''' <returns>
  179.         ''' The exact runtime type of the current instance.
  180.         ''' </returns>
  181.         ''' ----------------------------------------------------------------------------------------------------
  182.         <EditorBrowsable(EditorBrowsableState.Never)>
  183.         <DebuggerNonUserCode>
  184.         Public Shadows Function [GetType]() As Type
  185.             Return MyBase.GetType
  186.         End Function
  187.  
  188.         ''' ----------------------------------------------------------------------------------------------------
  189.         ''' <summary>
  190.         ''' Serves as a hash function for a particular type.
  191.         ''' </summary>
  192.         ''' ----------------------------------------------------------------------------------------------------
  193.         ''' <returns>
  194.         ''' A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
  195.         ''' </returns>
  196.         ''' ----------------------------------------------------------------------------------------------------
  197.         <EditorBrowsable(EditorBrowsableState.Never)>
  198.         <DebuggerNonUserCode>
  199.         Public Shadows Function GetHashCode() As Integer
  200.             Return MyBase.GetHashCode
  201.         End Function
  202.  
  203.         ''' ----------------------------------------------------------------------------------------------------
  204.         ''' <summary>
  205.         ''' Returns a String that represents the current object.
  206.         ''' </summary>
  207.         ''' ----------------------------------------------------------------------------------------------------
  208.         ''' <returns>
  209.         ''' A string that represents the current object.
  210.         ''' </returns>
  211.         ''' ----------------------------------------------------------------------------------------------------
  212.         <EditorBrowsable(EditorBrowsableState.Never)>
  213.         <DebuggerNonUserCode>
  214.         Public Shadows Function ToString() As String
  215.             Return MyBase.ToString
  216.         End Function
  217.  
  218. #End Region
  219.  
  220.     End Class
  221.  
  222. End Namespace
  223.  
  224. #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement