Comparisons.cs
author Dean
Fri, 02 Sep 2016 18:11:21 +0200
changeset 1238 55b7869062a7
child 1289 9422ede79073
permissions -rw-r--r--
Add IEquatable interface to PEPMessage, PEPAttachment and PEPIdentity.
Dean@1238
     1
´╗┐using System.Linq;
Dean@1238
     2
using System;
Dean@1238
     3
using System.Collections.Generic;
Dean@1238
     4
Dean@1238
     5
namespace pEp
Dean@1238
     6
{
Dean@1238
     7
    public static class Comparisons
Dean@1238
     8
    {
Dean@1238
     9
        /// <summary>
Dean@1238
    10
        /// Compares the given values and checks for equality.
Dean@1238
    11
        /// Null and empty cases are handled.
Dean@1238
    12
        /// </summary>
Dean@1238
    13
        /// <param name="value1">The first value to compare.</param>
Dean@1238
    14
        /// <param name="value2">The second value to compare with.</param>
Dean@1238
    15
        /// <returns>True if the values are considered equal, otherwise false.</returns>
Dean@1238
    16
        new public static bool Equals(object value1,
Dean@1238
    17
                                      object value2)
Dean@1238
    18
        {
Dean@1238
    19
            return (object.Equals(value1, value2));
Dean@1238
    20
        }
Dean@1238
    21
Dean@1238
    22
        /// <summary>
Dean@1238
    23
        /// Compares the given values and checks for equality.
Dean@1238
    24
        /// Null and empty cases are handled.
Dean@1238
    25
        /// </summary>
Dean@1238
    26
        /// <param name="value1">The first value to compare.</param>
Dean@1238
    27
        /// <param name="value2">The second value to compare with.</param>
Dean@1238
    28
        /// <returns>True if the values are considered equal, otherwise false.</returns>
Dean@1238
    29
        public static bool Equals<T>(IEnumerable<T> value1,
Dean@1238
    30
                                     IEnumerable<T> value2)
Dean@1238
    31
        {
Dean@1238
    32
            if ((value1 == null) ||
Dean@1238
    33
                (value2 == null))
Dean@1238
    34
            {
Dean@1238
    35
                if ((value1 != null) ||
Dean@1238
    36
                    (value2 != null))
Dean@1238
    37
                {
Dean@1238
    38
                    // One is null while the other is not
Dean@1238
    39
                    return (false);
Dean@1238
    40
                }
Dean@1238
    41
            }
Dean@1238
    42
            else
Dean@1238
    43
            {
Dean@1238
    44
                return (Enumerable.SequenceEqual(value1, value2));
Dean@1238
    45
            }
Dean@1238
    46
Dean@1238
    47
            return (true);
Dean@1238
    48
        }
Dean@1238
    49
Dean@1238
    50
    }
Dean@1238
    51
}