コード例 #1
0
        public void MemberInfoSlimEqualityComparer_Property_Index()
        {
            var tq = new TypeSlimEqualityComparer();
            var eq = new MemberInfoSlimEqualityComparer(tq);

            var asm = new AssemblySlim("foo");

            var tp1 = TypeSlim.Simple(asm, "bar");

            var i4 = typeof(int).ToTypeSlim();
            var i8 = typeof(long).ToTypeSlim();

            var indxs0 = new List <TypeSlim> {
                i4
            }.AsReadOnly();
            var indxs1 = new List <TypeSlim> {
                i8
            }.AsReadOnly();
            var indxs2 = new List <TypeSlim> {
                i4, i8
            }.AsReadOnly();
            var indxs3 = new List <TypeSlim> {
                i8, i4
            }.AsReadOnly();

            var prp_i4_0_0 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs0, canWrite: true);
            var prp_i4_0_1 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs0, canWrite: true);
            var prp_i4_1_0 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs1, canWrite: true);
            var prp_i4_2_0 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs2, canWrite: true);
            var prp_i4_3_0 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs3, canWrite: true);
            var prp_i4_3_1 = PropertyInfoSlim.Make(tp1, "Item", i4, indxs3, canWrite: true);

            var prp_i8_0_0 = PropertyInfoSlim.Make(tp1, "Item", i8, indxs0, canWrite: true);
            var prp_i8_1_0 = PropertyInfoSlim.Make(tp1, "Item", i8, indxs1, canWrite: true);
            var prp_i8_2_0 = PropertyInfoSlim.Make(tp1, "Item", i8, indxs2, canWrite: true);
            var prp_i8_3_0 = PropertyInfoSlim.Make(tp1, "Item", i8, indxs3, canWrite: true);

            Assert.IsTrue(eq.Equals(prp_i4_0_0, prp_i4_0_0));
            Assert.IsTrue(eq.Equals(prp_i4_0_0, prp_i4_0_1));
            Assert.IsTrue(eq.Equals(prp_i4_0_1, prp_i4_0_0));
            Assert.IsTrue(eq.Equals(prp_i4_3_0, prp_i4_3_1));
            Assert.IsTrue(eq.Equals(prp_i4_3_1, prp_i4_3_0));

            Assert.IsFalse(eq.Equals(prp_i4_0_0, prp_i4_1_0));
            Assert.IsFalse(eq.Equals(prp_i4_1_0, prp_i4_0_0));
            Assert.IsFalse(eq.Equals(prp_i4_2_0, prp_i4_3_0));
            Assert.IsFalse(eq.Equals(prp_i4_3_0, prp_i4_2_0));

            Assert.IsFalse(eq.Equals(prp_i4_0_0, prp_i8_0_0));
            Assert.IsFalse(eq.Equals(prp_i4_1_0, prp_i8_1_0));
            Assert.IsFalse(eq.Equals(prp_i4_2_0, prp_i8_2_0));
            Assert.IsFalse(eq.Equals(prp_i4_3_0, prp_i8_3_0));

            Assert.AreEqual(eq.GetHashCode(prp_i4_0_0), eq.GetHashCode(prp_i4_0_1));
            Assert.AreEqual(eq.GetHashCode(prp_i4_3_0), eq.GetHashCode(prp_i4_3_1));
        }
コード例 #2
0
        public void MemberInfoSlimEqualityComparer_Property_NoIndex()
        {
            var tq = new TypeSlimEqualityComparer();
            var eq = new MemberInfoSlimEqualityComparer(tq);

            var asm = new AssemblySlim("foo");

            var tp1 = TypeSlim.Simple(asm, "bar");
            var tp2 = TypeSlim.Simple(asm, "baz");

            var i4 = typeof(int).ToTypeSlim();
            var i8 = typeof(long).ToTypeSlim();

            var indxs = Array.Empty <TypeSlim>().ToList().AsReadOnly();

            var prp11_0 = PropertyInfoSlim.Make(tp1, "qux1", i4, indxs, canWrite: true);
            var prp12_0 = PropertyInfoSlim.Make(tp1, "qux2", i4, indxs, canWrite: true);
            var prp13_0 = PropertyInfoSlim.Make(tp1, "qux3", i8, indxs, canWrite: true);

            var prp11_1 = PropertyInfoSlim.Make(tp1, "qux1", i4, indxs, canWrite: true);
            var prp12_1 = PropertyInfoSlim.Make(tp1, "qux2", i4, indxs, canWrite: true);
            var prp13_1 = PropertyInfoSlim.Make(tp1, "qux3", i8, indxs, canWrite: true);

            var prp21_0 = PropertyInfoSlim.Make(tp2, "qux1", i4, indxs, canWrite: true);

            Assert.IsTrue(eq.Equals(prp11_0, prp11_0));
            Assert.IsTrue(eq.Equals(prp11_0, prp11_1));
            Assert.IsTrue(eq.Equals(prp11_1, prp11_0));
            Assert.IsTrue(eq.Equals(prp11_1, prp11_1));

            Assert.IsTrue(eq.Equals(prp12_0, prp12_0));
            Assert.IsTrue(eq.Equals(prp12_0, prp12_1));
            Assert.IsTrue(eq.Equals(prp12_1, prp12_0));
            Assert.IsTrue(eq.Equals(prp12_1, prp12_1));

            Assert.IsTrue(eq.Equals(prp13_0, prp13_0));
            Assert.IsTrue(eq.Equals(prp13_0, prp13_1));
            Assert.IsTrue(eq.Equals(prp13_1, prp13_0));
            Assert.IsTrue(eq.Equals(prp13_1, prp13_1));

            Assert.IsFalse(eq.Equals(prp11_0, prp12_0));
            Assert.IsFalse(eq.Equals(prp12_0, prp11_0));
            Assert.IsFalse(eq.Equals(prp11_0, prp21_0));
            Assert.IsFalse(eq.Equals(prp21_0, prp11_0));

            Assert.AreEqual(eq.GetHashCode(prp11_0), eq.GetHashCode(prp11_1));
            Assert.AreEqual(eq.GetHashCode(prp12_0), eq.GetHashCode(prp12_1));
            Assert.AreEqual(eq.GetHashCode(prp13_0), eq.GetHashCode(prp13_1));
        }
コード例 #3
0
        public void MemberInfoSlimEqualityComparer_Trivialities()
        {
            var tq = new TypeSlimEqualityComparer();
            var eq = new MemberInfoSlimEqualityComparer(tq);

            var i4 = typeof(int).ToTypeSlim();
            var fl = new FieldInfoSlim(i4, "foo", i4);
            var pr = PropertyInfoSlim.Make(i4, "bar", i4, new List <TypeSlim>().AsReadOnly(), canWrite: true);

            Assert.IsTrue(eq.Equals(null, null));
            Assert.AreEqual(eq.GetHashCode(null), eq.GetHashCode(null));

            Assert.IsFalse(eq.Equals(fl, null));
            Assert.IsFalse(eq.Equals(null, fl));

            Assert.IsFalse(eq.Equals(fl, pr));
            Assert.IsFalse(eq.Equals(pr, fl));
        }