Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' ***********************************************************************
- ' Author : Elektro
- ' Modified : 06-January-2016
- ' ***********************************************************************
- #Region " Public Members Summary "
- #Region " Constructors "
- ' New()
- #End Region
- #Region " Functions "
- ' Compare(Object, Object) As Integer : Implements IComparer.Compare
- #End Region
- #End Region
- #Region " Option Statements "
- Option Strict On
- Option Explicit On
- Option Infer Off
- #End Region
- #Region " Imports "
- Imports System
- Imports System.Collections
- Imports System.ComponentModel
- Imports System.Diagnostics
- Imports System.Linq
- Imports Elektro.Application.UI.Enums
- #End Region
- #Region " Numeric Comparer "
- Namespace Types
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Performs a comparison between two numeric values.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- Public NotInheritable Class NumericComparer : Implements IComparer
- #Region " Constructors "
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Initializes a new instance of the <see cref="NumericComparer"/> class.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerNonUserCode>
- Public Sub New()
- End Sub
- #End Region
- #Region " Public Methods "
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="a">
- ''' The first object to compare.
- ''' </param>
- '''
- ''' <param name="b">
- ''' The second object to compare.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' A signed integer that indicates the relative values of <paramref name="a"/> and <paramref name="b"/>.
- ''' <para></para>
- ''' 0: <paramref name="a"/> equals <paramref name="b"/>.
- ''' <para></para>
- ''' Less than 0: <paramref name="a" /> is less than <paramref name="b"/>.
- ''' <para></para>
- ''' Greater than 0: <paramref name="a"/> is greater than <paramref name="b"/>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Function Compare(ByVal a As Object, ByVal b As Object) As Integer Implements IComparer.Compare
- ' Null parsing.
- If a Is Nothing AndAlso b Is Nothing Then
- Return ComparerResult.Equals ' A is equals to B.
- ElseIf a Is Nothing AndAlso b IsNot Nothing Then
- Return ComparerResult.LessThan ' A is less than B.
- ElseIf a IsNot Nothing AndAlso b Is Nothing Then
- Return ComparerResult.GreaterThan ' A is greater than B.
- Else
- Dim singleA As Single
- Dim singleB As Single
- If Single.TryParse(CStr(a), singleA) AndAlso Single.TryParse(CStr(b), singleB) Then ' True And True.
- Return DirectCast(singleA.CompareTo(singleB), ComparerResult)
- ElseIf Single.TryParse(CStr(a), singleA) AndAlso Not Single.TryParse(CStr(b), singleB) Then ' True And False.
- Return ComparerResult.GreaterThan ' A is greater than B.
- ElseIf Not Single.TryParse(CStr(a), singleA) AndAlso Single.TryParse(CStr(b), singleB) Then ' False And True.
- Return ComparerResult.LessThan ' A is less than B.
- Else ' False And False.
- Return DirectCast(a.ToString.CompareTo(b.ToString), ComparerResult)
- End If
- End If
- End Function
- #End Region
- #Region " Hidden Base Members "
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Determines whether the specified <see cref="Object"/> is equal to this instance.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="obj">
- ''' Another object to compare to.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' <see langword="True"/> if the specified <see cref="Object"/> is equal to this instance; otherwise, <see langword="False"/>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <EditorBrowsable(EditorBrowsableState.Never)>
- <DebuggerNonUserCode>
- Public Shadows Function Equals(ByVal obj As Object) As Boolean
- Return MyBase.Equals(obj)
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Determines whether the specified <see cref="System.Object"/> instances are the same instance.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="objA">
- ''' The first object to compare.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="objB">
- ''' The second object to compare.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' <see langword="True"/> if <paramref name="objA"/> is the same instance as <paramref name="objB"/>
- ''' or if both are <see langword="Nothing"/>; otherwise, <see langword="False"/>.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <EditorBrowsable(EditorBrowsableState.Never)>
- <DebuggerNonUserCode>
- Public Shadows Function ReferenceEquals(ByVal objA As Object, ByVal objB As Object) As Boolean
- Return Object.ReferenceEquals(objA, objB)
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the <see cref="System.Type"/> of the current instance.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' The exact runtime type of the current instance.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <EditorBrowsable(EditorBrowsableState.Never)>
- <DebuggerNonUserCode>
- Public Shadows Function [GetType]() As Type
- Return MyBase.GetType
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Serves as a hash function for a particular type.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <EditorBrowsable(EditorBrowsableState.Never)>
- <DebuggerNonUserCode>
- Public Shadows Function GetHashCode() As Integer
- Return MyBase.GetHashCode
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Returns a String that represents the current object.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' A string that represents the current object.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- <EditorBrowsable(EditorBrowsableState.Never)>
- <DebuggerNonUserCode>
- Public Shadows Function ToString() As String
- Return MyBase.ToString
- End Function
- #End Region
- End Class
- End Namespace
- #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement