コード例 #1
0
        public void EqualsArray()
        {
            var now    = DateTime.Now;
            var array1 = new object[]
            {
                "string",
                123,
                123.5d,
                45.67m,
                now
            };
            var array2 = new object[]
            {
                "string",
                123,
                123.5d,
                45.67m,
                now
            };
            var array3 = new object[]
            {
                "string",
                444,
                123.5d,
                45.67m,
                now
            };

            Assert.AreEqual(true, DefaultComparer.Equals(array1, array1));
            Assert.AreEqual(true, DefaultComparer.Equals(array1, array2));
            Assert.AreEqual(false, DefaultComparer.Equals(array1, array3));
        }
コード例 #2
0
        public void Equals_Check(int?testValue1, int?testValue2, bool expected)
        {
            var comparer = new DefaultComparer();
            var result   = comparer.Equals(testValue1, testValue2);

            Assert.Equal(expected, result);
        }
コード例 #3
0
        public async Task LicensesEqual()
        {
            const string MIT = @"MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the ""Software""), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/ or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.";

            string license = await new GitHubLicenseUrlReader()
                             .GetLicenseTextAsync("https://raw.githubusercontent.com/lvermeulen/Flurl.Http.Xml/master/LICENSE");

            var  comparer = new DefaultComparer(MIT);
            bool equal    = comparer.Equals(license);

            Assert.True(equal);
        }
コード例 #4
0
        /// <summary>
        /// Writes all fields of the object to the specified section (replacing a present one).
        /// </summary>
        /// <param name="section">The section to write to.</param>
        /// <param name="type">Type of <paramref name="item"/></param>
        /// <param name="item">The instance to write.</param>
        public void WriteFields(string section, Type type, object item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            foreach (var field in item.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (field.HasAttribute <IniIgnoreAttribute>())
                {
                    continue;
                }

                var value = field.GetValue(item);

                if (field.HasAttribute <IniSectionAttribute>())
                {
                    var sectionAttribute = field.GetAttribute <IniSectionAttribute>();
                    if (value is null)
                    {
                        continue;
                    }

                    if (value is IEnumerable enumerable)
                    {
                        throw new NotSupportedException("Arrays are not (yet) supported!");
                    }

                    switch (sectionAttribute.SettingsType)
                    {
                    case IniSettingsType.Fields: WriteFields(sectionAttribute.Name ?? field.Name, field.FieldType, value); continue;

                    case IniSettingsType.Properties: WriteProperties(sectionAttribute.Name ?? field.Name, field.FieldType, value); continue;

                    default: throw new NotImplementedException($"IniSettingsType.{sectionAttribute.SettingsType} not implemented at {GetType()}!");
                    }
                }
                else if (!SkipRoundTripTests)
                {
                    //roundtrip test
                    try
                    {
                        var data      = StringExtensions.ToString(value, Properties.Culture);
                        var test      = TypeExtension.ConvertValue(field.FieldType, data, Properties.Culture);
                        var container = Activator.CreateInstance(type);
                        field.SetValue(container, test);
                        if (!DefaultComparer.Equals(test, value))
                        {
                            throw new InvalidDataException($"Equals test at field {field} failed! Value = {test}, expected = {value}");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidDataException($"Roundtrip w/r test for field {field} failed!", ex);
                    }
                }
                WriteSetting(section, field.Name, value);
            }
        }
コード例 #5
0
ファイル: TestStruct.cs プロジェクト: elfen20/clone-cave-data
        public override bool Equals(object obj)
        {
            if (!(obj is TestStructClean))
            {
                return(false);
            }
            var other = (TestStructClean)obj;

            return
                (DefaultComparer.Equals(this.Arr, other.Arr) &&
                 Equals(this.B, other.B) &&
                 Equals(this.C, other.C) &&
                 Equals(this.ConStr, other.ConStr) &&
                 Equals(this.D, other.D) &&
                 Equals(this.Date, other.Date) &&
                 Equals(this.Dec, other.Dec) &&
                 Equals(this.F, other.F) &&
                 Equals(this.I, other.I) &&
                 Equals(this.S, other.S) &&
                 Equals(this.SB, other.SB) &&
                 Equals(this.Text, other.Text) &&
                 Equals(this.Time, other.Time) &&
                 Equals(this.UI, other.UI) &&
                 Equals(this.Uri, other.Uri) &&
                 Equals(this.US, other.US));
        }
コード例 #6
0
        public void EqualsStruct()
        {
            var s1 = InteropTestStruct.Create(1);
            var s2 = InteropTestStruct.Create(1);
            var s3 = InteropTestStruct.Create(3);

            Assert.AreEqual(true, DefaultComparer.Equals(s1, s1));
            Assert.AreEqual(true, DefaultComparer.Equals(s1, s2));
            Assert.AreEqual(false, DefaultComparer.Equals(s1, s3));
            object o1 = s1;
            object o2 = s2;
            object o3 = s3;

            Assert.AreEqual(true, DefaultComparer.Equals(o1, o1));
            Assert.AreEqual(true, DefaultComparer.Equals(o2, o1));
            Assert.AreEqual(false, DefaultComparer.Equals(o3, o1));
        }
コード例 #7
0
ファイル: Row.cs プロジェクト: elfen20/clone-cave-data
        /// <summary>Equalses the specified other.</summary>
        /// <param name="other">The other.</param>
        /// <returns><c>true</c> if the specified <see cref="Row" /> is equal to this instance; otherwise, <c>false</c>.</returns>
        public bool Equals(Row other)
        {
            if (other?.Values?.Length != Values.Length)
            {
                return(false);
            }

            for (var i = 0; i < Values.Length; i++)
            {
                var source = Values[i];
                var target = other.Values[i];
                if (!DefaultComparer.Equals(source, target))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #8
0
        public void TestCultureEqual()
        {
            var savedCurrentCulture   = CultureInfo.CurrentCulture;
            var savedCurrentUICulture = CultureInfo.CurrentUICulture;
            var rnd = new Random();

            foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                if (culture.IsNeutralCulture)
                {
                    continue;
                }

                if (Program.Verbose)
                {
                    Console.WriteLine(culture);
                }
                Thread.CurrentThread.CurrentCulture   = culture;
                Thread.CurrentThread.CurrentUICulture = culture;
                for (var i = 0; i < 1000; i++)
                {
                    var dt1 = new DateTime(rnd.Next() + DateTime.Now.Ticks, DateTimeKind.Unspecified);
                    var dt2 = new DateTime(dt1.Ticks, DateTimeKind.Local);
                    Assert.AreEqual(true, DefaultComparer.Equals(dt1, dt1));
                    Assert.AreEqual(true, DefaultComparer.Equals(dt1, dt2));
                    Assert.AreEqual(true, DefaultComparer.Equals(dt2, dt1));
                    Assert.AreEqual(true, DefaultComparer.Equals(dt1, dt2.ToUniversalTime()));
                    Assert.AreEqual(true, DefaultComparer.Equals(dt2.ToUniversalTime(), dt1));
                    Assert.AreEqual(true, DefaultComparer.Equals(dt1, dt2.ToLocalTime()));
                    Assert.AreEqual(true, DefaultComparer.Equals(dt2.ToLocalTime(), dt1));
                    Assert.AreEqual(true, DefaultComparer.Equals(dt2.ToLocalTime(), dt2.ToUniversalTime()));
                    Assert.AreEqual(true, DefaultComparer.Equals(dt2.ToUniversalTime(), dt2.ToLocalTime()));
                }
            }

            Thread.CurrentThread.CurrentCulture   = savedCurrentCulture;
            Thread.CurrentThread.CurrentUICulture = savedCurrentUICulture;
        }
コード例 #9
0
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(IPageResponse other)
 {
     return(DefaultComparer.Equals(this, other));
 }
コード例 #10
0
ファイル: User.cs プロジェクト: CaveSystems/cave-auth
        /// <summary>Tests the password.</summary>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public bool TestPassword(string password)
        {
            var data = GetPasswordBytes(password);

            return(DefaultComparer.Equals(data, PasswordBytes));
        }
コード例 #11
0
 public static bool operator ==(EquatableExpression a, EquatableExpression b)
 {
     return(DefaultComparer.Equals(a, b));
 }
コード例 #12
0
 public override bool Equals(object obj)
 {
     return(DefaultComparer.Equals(this, obj as EquatableExpression));
 }
コード例 #13
0
 public bool Equals(EquatableExpression other)
 {
     return(DefaultComparer.Equals(this, other));
 }
コード例 #14
0
        /// <summary>
        /// Writes all properties of the object to the specified section (replacing a present one).
        /// </summary>
        /// <param name="section">The section to write to.</param>
        /// <param name="type">Type of <paramref name="item"/></param>
        /// <param name="item">The instance to write.</param>
        public void WriteProperties(string section, Type type, object item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            foreach (var property in item.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (property.HasAttribute <IniIgnoreAttribute>())
                {
                    continue;
                }

                var value = property.GetValue(item, null);

                if (property.HasAttribute <IniSectionAttribute>())
                {
                    var sectionAttribute = property.GetAttribute <IniSectionAttribute>();
                    if (value is null)
                    {
                        continue;
                    }

                    if (value is IEnumerable enumerable)
                    {
                        throw new NotSupportedException("Arrays are not (yet) supported!");
                    }

                    switch (sectionAttribute.SettingsType)
                    {
                    case IniSettingsType.Fields: WriteFields(sectionAttribute.Name ?? property.Name, property.PropertyType, value); continue;

                    case IniSettingsType.Properties: WriteProperties(sectionAttribute.Name ?? property.Name, property.PropertyType, value); continue;

                    default: throw new NotImplementedException($"IniSettingsType.{sectionAttribute.SettingsType} not implemented at {GetType()}!");
                    }
                }
                else if (!SkipRoundTripTests)
                {
                    //roundtrip test
                    try
                    {
                        var data      = StringExtensions.ToString(value, Properties.Culture);
                        var test      = TypeExtension.ConvertValue(property.PropertyType, data, Properties.Culture);
                        var container = Activator.CreateInstance(type);
                        property.SetValue(container, test, null);
                        if (!DefaultComparer.Equals(test, value))
                        {
                            throw new InvalidDataException($"Equals() check failed! Written: {value}, Read: {test}");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidDataException($"Write/Read round trip test failed! You can swith this off with {nameof(IniWriter)}.{nameof(SkipRoundTripTests)}", ex);
                    }
                }

                WriteSetting(section, property.Name, value);
            }
        }
コード例 #15
0
ファイル: FilePath.cs プロジェクト: ailen0ada/Mio
 public static bool Equals([CanBeNull] FilePath x, [CanBeNull] FilePath y)
 => DefaultComparer.Equals(x, y);
コード例 #16
0
        /// <summary>
        /// Determines whether the specified Object is equal to the current Object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            var other = obj as IAudioData;

            return(other == null ? false : Equals(other) && DefaultComparer.Equals(other.Data, Data));
        }
コード例 #17
0
 /// <summary>
 ///     Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <returns>
 ///     true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
 /// </returns>
 /// <param name="other">An object to compare with this object.</param>
 public bool Equals(IVirtualResponse?other)
 {
     return(DefaultComparer.Equals(this, other));
 }
コード例 #18
0
 /// <inheritdoc />
 public bool Equals(IPageRequest?other)
 {
     return(DefaultComparer.Equals(this, other));
 }
コード例 #19
0
ファイル: Claim.cs プロジェクト: pmq20/mono_forked
        public override bool Equals(object obj)
        {
            Claim c = obj as Claim;

            return(c != null && DefaultComparer.Equals(this, c));
        }