Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.01 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
  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 " Text Comparer "
  43.  
  44. Namespace Types
  45.  
  46.     ''' ----------------------------------------------------------------------------------------------------
  47.     ''' <summary>
  48.     ''' Performs a comparison between two string values.
  49.     ''' </summary>
  50.     ''' ----------------------------------------------------------------------------------------------------
  51.     Public NotInheritable Class TextComparer : Inherits CaseInsensitiveComparer
  52.  
  53. #Region " Constructors "
  54.  
  55.         ''' ----------------------------------------------------------------------------------------------------
  56.         ''' <summary>
  57.         ''' Initializes a new instance of the <see cref="TextComparer"/> 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 Shadows Function Compare(ByVal a As Object, ByVal b As Object) As Integer
  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.                 If (TypeOf a Is String) AndAlso (TypeOf b Is String) Then ' True And True.
  106.                     Return DirectCast(MyBase.Compare(a, b), ComparerResult)
  107.  
  108.                 ElseIf (TypeOf a Is String) AndAlso Not (TypeOf b Is String) Then ' True And False.
  109.                     Return ComparerResult.GreaterThan ' A is greater than B.
  110.  
  111.                 ElseIf Not (TypeOf a Is String) AndAlso (TypeOf b Is String) Then ' False And True.
  112.                     Return ComparerResult.LessThan ' A is less than B.
  113.  
  114.                 Else ' False And False.
  115.                     Return ComparerResult.Equals
  116.  
  117.                 End If
  118.  
  119.             End If
  120.  
  121.         End Function
  122.  
  123. #End Region
  124.  
  125. #Region " Hidden Base Members "
  126.  
  127.         ''' ----------------------------------------------------------------------------------------------------
  128.         ''' <summary>
  129.         ''' Determines whether the specified <see cref="Object"/> is equal to this instance.
  130.         ''' </summary>
  131.         ''' ----------------------------------------------------------------------------------------------------
  132.         ''' <param name="obj">
  133.         ''' Another object to compare to.
  134.         ''' </param>
  135.         ''' ----------------------------------------------------------------------------------------------------
  136.         ''' <returns>
  137.         ''' <see langword="True"/> if the specified <see cref="Object"/> is equal to this instance; otherwise, <see langword="False"/>.
  138.         ''' </returns>
  139.         ''' ----------------------------------------------------------------------------------------------------
  140.         <EditorBrowsable(EditorBrowsableState.Never)>
  141.         <DebuggerNonUserCode>
  142.         Public Shadows Function Equals(ByVal obj As Object) As Boolean
  143.             Return MyBase.Equals(obj)
  144.         End Function
  145.  
  146.         ''' ----------------------------------------------------------------------------------------------------
  147.         ''' <summary>
  148.         ''' Determines whether the specified <see cref="System.Object"/> instances are the same instance.
  149.         ''' </summary>
  150.         ''' ----------------------------------------------------------------------------------------------------
  151.         ''' <param name="objA">
  152.         ''' The first object to compare.
  153.         ''' </param>
  154.         ''' ----------------------------------------------------------------------------------------------------
  155.         ''' <param name="objB">
  156.         ''' The second object to compare.
  157.         ''' </param>
  158.         ''' ----------------------------------------------------------------------------------------------------
  159.         ''' <returns>
  160.         ''' <see langword="True"/> if <paramref name="objA"/> is the same instance as <paramref name="objB"/>
  161.         ''' or if both are <see langword="Nothing"/>; otherwise, <see langword="False"/>.
  162.         ''' </returns>
  163.         ''' ----------------------------------------------------------------------------------------------------
  164.         <EditorBrowsable(EditorBrowsableState.Never)>
  165.         <DebuggerNonUserCode>
  166.         Public Shadows Function ReferenceEquals(ByVal objA As Object, ByVal objB As Object) As Boolean
  167.             Return Object.ReferenceEquals(objA, objB)
  168.         End Function
  169.  
  170.         ''' ----------------------------------------------------------------------------------------------------
  171.         ''' <summary>
  172.         ''' Gets the <see cref="System.Type"/> of the current instance.
  173.         ''' </summary>
  174.         ''' ----------------------------------------------------------------------------------------------------
  175.         ''' <returns>
  176.         ''' The exact runtime type of the current instance.
  177.         ''' </returns>
  178.         ''' ----------------------------------------------------------------------------------------------------
  179.         <EditorBrowsable(EditorBrowsableState.Never)>
  180.         <DebuggerNonUserCode>
  181.         Public Shadows Function [GetType]() As Type
  182.             Return MyBase.GetType
  183.         End Function
  184.  
  185.         ''' ----------------------------------------------------------------------------------------------------
  186.         ''' <summary>
  187.         ''' Serves as a hash function for a particular type.
  188.         ''' </summary>
  189.         ''' ----------------------------------------------------------------------------------------------------
  190.         ''' <returns>
  191.         ''' A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
  192.         ''' </returns>
  193.         ''' ----------------------------------------------------------------------------------------------------
  194.         <EditorBrowsable(EditorBrowsableState.Never)>
  195.         <DebuggerNonUserCode>
  196.         Public Shadows Function GetHashCode() As Integer
  197.             Return MyBase.GetHashCode
  198.         End Function
  199.  
  200.         ''' ----------------------------------------------------------------------------------------------------
  201.         ''' <summary>
  202.         ''' Returns a String that represents the current object.
  203.         ''' </summary>
  204.         ''' ----------------------------------------------------------------------------------------------------
  205.         ''' <returns>
  206.         ''' A string that represents the current object.
  207.         ''' </returns>
  208.         ''' ----------------------------------------------------------------------------------------------------
  209.         <EditorBrowsable(EditorBrowsableState.Never)>
  210.         <DebuggerNonUserCode>
  211.         Public Shadows Function ToString() As String
  212.             Return MyBase.ToString
  213.         End Function
  214.  
  215. #End Region
  216.  
  217.     End Class
  218.  
  219. End Namespace
  220.  
  221. #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement