Beispiel #1
0
    static int pass_struct_spill_big(TestStruct3 regStruct)
    {
        int retVal;

        retVal = receive_struct_spill_big(1, 2, 3, 4, 5, regStruct);
        return(retVal);
    }
Beispiel #2
0
    static int pass_spill_struct_spill_big(int a, int b, int c, int d, int e, TestStruct3 regStruct)
    {
        int retVal;

        retVal = receive_struct_spill_big(a, b, c, d, e, regStruct);
        return(retVal);
    }
Beispiel #3
0
        public void ReadSameAlignementStructNonNativeEndian()
        {
            // Will test the fast path with mixed types but same alignement
            byte[] data = new byte[8 * 3];
            Array.Copy(BitConverter.GetBytes((long)1), 0, data, 0, 8);
            Array.Copy(BitConverter.GetBytes(ulong.MaxValue), 0, data, 8, 8);
            Array.Copy(BitConverter.GetBytes((double)3.3), 0, data, 16, 8);
            // Swap value to simulate other endianness
            for (int i = 0; i < data.Length; i += 8)
            {
                for (int j = 0; j < 4; j++)
                {
                    data[i + j]     = (byte)(data[i + j] ^ data[i + 7 - j]);
                    data[i + 7 - j] = (byte)(data[i + j] ^ data[i + 7 - j]);
                    data[i + j]     = (byte)(data[i + j] ^ data[i + 7 - j]);
                }
            }

            MessageReader reader = new MessageReader(!BitConverter.IsLittleEndian ? EndianFlag.Little : EndianFlag.Big, data);

            TestStruct3 stct = (TestStruct3)reader.ReadStruct(typeof(TestStruct3));

            Assert.AreEqual(1, stct.Item1);
            Assert.AreEqual(ulong.MaxValue, stct.Item2);
            Assert.AreEqual(3.3, stct.Item3);
        }
Beispiel #4
0
    static TestStruct3 ret_big_struct(int value_a, int value_c)
    {
        TestStruct3 regStruct = new TestStruct3();

        regStruct.a = value_a;
        regStruct.c = value_c;
        return(regStruct);
    }
Beispiel #5
0
 static int receive_spill_struct_big(TestStruct3 regStruct)
 {
     if (regStruct.c == 999)
     {
         return(0);
     }
     else
     {
         return(9);
     }
 }
Beispiel #6
0
 static int spill_struct_void(TestStruct3 regStruct)
 {
     if (regStruct.c == 255)
     {
         return(0);
     }
     else
     {
         return(7);
     }
 }
Beispiel #7
0
 static int receive_struct_spill_big(int a, int b, int c, int d, int e, TestStruct3 regStruct)
 {
     if (regStruct.c == 999)
     {
         return(0);
     }
     else
     {
         return(11);
     }
 }
        public void Sr_ReadLeInt32_Padding()
        {
            var rdr = new LeImageReader(new byte[] { 
                0x34, 0x12,
                0xAB, 0xCD, 
                0x78, 0x56, 0x34, 0x12 }, 0);
            var test = new TestStruct3();
            var sr = new StructureReader(test);
            sr.Read(rdr);

            Assert.AreEqual((int) 0x12345678, test.lField);
        }
Beispiel #9
0
        public void Sr_ReadLeInt32_Padding()
        {
            var rdr = new LeImageReader(new byte[] {
                0x34, 0x12,
                0xAB, 0xCD,
                0x78, 0x56, 0x34, 0x12
            }, 0);
            var test = new TestStruct3();
            var sr   = new StructureReader(test);

            sr.Read(rdr);

            Assert.AreEqual((int)0x12345678, test.lField);
        }
Beispiel #10
0
        public void ReadSameAlignementStructNativeEndian()
        {
            // Will test the fast path with mixed types but same alignement
            byte[] data = new byte[8 * 3];
            Array.Copy(BitConverter.GetBytes((long)1), 0, data, 0, 8);
            Array.Copy(BitConverter.GetBytes(ulong.MaxValue), 0, data, 8, 8);
            Array.Copy(BitConverter.GetBytes((double)3.3), 0, data, 16, 8);

            MessageReader reader = new MessageReader(BitConverter.IsLittleEndian ? EndianFlag.Little : EndianFlag.Big, data);

            TestStruct3 stct = (TestStruct3)reader.ReadStruct(typeof(TestStruct3));

            Assert.AreEqual(1, stct.Item1);
            Assert.AreEqual(ulong.MaxValue, stct.Item2);
            Assert.AreEqual(3.3, stct.Item3);
        }
Beispiel #11
0
 static int spill_struct_ret(TestStruct3 regStruct)
 {
     return(regStruct.c);
 }
Beispiel #12
0
 static TestStruct3 ret_big_struct(int value_a, int value_c)
 {
     TestStruct3 regStruct = new TestStruct3();
     regStruct.a = value_a;
     regStruct.c = value_c;
     return (regStruct);
 }
Beispiel #13
0
 static TestStruct3 spill_struct(TestStruct3 regStruct, int value)
 {
     regStruct.c = value;
     return (regStruct);
 }
Beispiel #14
0
    static int spill_struct_ret(TestStruct3 regStruct)
    {
        return (regStruct.c);

    }
Beispiel #15
0
 static int pass_spill_struct_spill_big(int a, int b, int c, int d, int e, TestStruct3 regStruct)
 {
     int retVal;
     retVal = receive_struct_spill_big(a, b, c, d, e, regStruct);
     return retVal;
 }
Beispiel #16
0
 static int pass_struct_spill_big(TestStruct3 regStruct)
 {
     int retVal;
     retVal = receive_struct_spill_big(1, 2, 3, 4, 5, regStruct);
     return retVal;
 }
Beispiel #17
0
 static int receive_struct_spill_big(int a, int b, int c, int d, int e, TestStruct3 regStruct)
 {
     if (regStruct.c == 999)
         return 0;
     else
         return 11;
 }
Beispiel #18
0
 static int receive_spill_struct_big(TestStruct3 regStruct)
 {
     if (regStruct.c == 999)
         return 0;
     else
         return 9;
 }
Beispiel #19
0
    public unsafe static int Main()
    {
        ///
        ///	Testing simple struct size
        ///
        if (Marshal.SizeOf(typeof(TestStruct1)) != 32)
        {
            return(1);
        }

        TestStruct1 myStruct = new TestStruct1();

        myStruct.a = 0x12345678;

        IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TestStruct1)));

        Marshal.StructureToPtr(myStruct, p, false);

        Type testType = typeof(TestStruct1);

        if (Marshal.ReadInt32(p, (int)Marshal.OffsetOf(testType, "a")) != myStruct.a)
        {
            return(2);
        }

        Marshal.FreeHGlobal(p);

        ///
        ///	Testing struct size with ByValTStr string
        ///
        if (Marshal.SizeOf(typeof(TestStruct2)) != 32)
        {
            return(3);
        }

        TestStruct2 myStruct2 = new TestStruct2();

        myStruct2.b = 0x12345678;

        p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TestStruct2)));
        Marshal.StructureToPtr(myStruct2, p, false);

        Type testType2 = typeof(TestStruct2);

        if (Marshal.ReadInt32(p, (int)Marshal.OffsetOf(testType2, "b")) != myStruct2.b)
        {
            return(4);
        }

        Marshal.FreeHGlobal(p);

        ///
        ///	Test structure size and struct with inheritance
        ///
        if (Marshal.SizeOf(typeof(TestStruct3)) != 64)
        {
            return(5);
        }

        TestStruct3 myStruct3 = new TestStruct3();

        myStruct3.b = 0x12345678;
        myStruct3.c = 0x76543210;
        p           = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TestStruct3)));
        Marshal.StructureToPtr(myStruct3, p, false);

        Type testType3 = typeof(TestStruct3);

        if (Marshal.ReadInt32(p, (int)Marshal.OffsetOf(testType3, "b")) != myStruct3.b)
        {
            return(6);
        }

        if (Marshal.ReadInt32(p, (int)Marshal.OffsetOf(testType3, "c")) != myStruct3.c)
        {
            return(7);
        }

        Marshal.FreeHGlobal(p);

        ///
        ///	Also make sure OffsetOf returns the correct Exception.
        ///
        try {
            Marshal.OffsetOf(testType3, "blah");
            return(8);
        }
        catch (ArgumentException e)  {
            /// Way to go :)
        }
        catch (Exception e) {
            return(9);
        }

        // test size of structs with objects
        if (Marshal.SizeOf(typeof(TestStruct4)) != IntPtr.Size)
        {
            return(10);
        }
        if (Marshal.SizeOf(typeof(TestStruct5)) != IntPtr.Size)
        {
            return(11);
        }
        if (Marshal.SizeOf(typeof(TestStruct6)) != IntPtr.Size)
        {
            return(12);
        }
        // a VARIANT is
        if (Marshal.SizeOf(typeof(TestStruct7)) != 16)
        {
            return(13);
        }
        if (IsOSX() && IntPtr.Size == 4)
        {
            if (Marshal.SizeOf(typeof(TestStruct8)) != 12)
            {
                return(14);
            }
            if (Marshal.SizeOf(typeof(TestStruct10)) != 12)
            {
                return(16);
            }
        }
        else
        {
            if (Marshal.SizeOf(typeof(TestStruct8)) != 16 && Marshal.SizeOf(typeof(TestStruct8)) != 12)
            {
                return(14);
            }
            if (Marshal.SizeOf(typeof(TestStruct10)) != 16 && Marshal.SizeOf(typeof(TestStruct10)) != 12)
            {
                return(16);
            }
        }
        if (Marshal.SizeOf(typeof(TestStruct9)) != 12)
        {
            return(15);
        }
        if (Marshal.SizeOf(typeof(TestStruct11)) != 11)
        {
            return(17);
        }
        if (Marshal.SizeOf(typeof(TestStruct12)) != 6)
        {
            return(18);
        }
        if (Marshal.SizeOf(typeof(TestStruct13)) != 12)
        {
            return(19);
        }
        if (Marshal.SizeOf(typeof(TestStruct14)) != 12)
        {
            return(20);
        }
        return(0);
    }
Beispiel #20
0
	public unsafe static int Main () 
	{
		///
		///	Testing simple struct size
		///
		if(Marshal.SizeOf(typeof(TestStruct1)) != 32)
		{
			return 1;
		}

		TestStruct1 myStruct = new TestStruct1();
		myStruct.a = 0x12345678;

		IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TestStruct1)));
		Marshal.StructureToPtr(myStruct, p, false);

		Type testType = typeof(TestStruct1);
		if (Marshal.ReadInt32(p, (int)Marshal.OffsetOf(testType, "a")) != myStruct.a)
			return 2;

		Marshal.FreeHGlobal(p);

		///
		///	Testing struct size with ByValTStr string
		///
		if(Marshal.SizeOf(typeof(TestStruct2)) != 32)
			return 3;

		TestStruct2 myStruct2 = new TestStruct2();
		myStruct2.b = 0x12345678;

		p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TestStruct2)));
		Marshal.StructureToPtr(myStruct2, p, false);

		Type testType2 = typeof(TestStruct2);
		if (Marshal.ReadInt32(p, (int)Marshal.OffsetOf(testType2, "b")) != myStruct2.b)
			return 4;

		Marshal.FreeHGlobal(p);

		///
		///	Test structure size and struct with inheritance
		///
		if(Marshal.SizeOf(typeof(TestStruct3)) != 64)
			return 5;

		TestStruct3 myStruct3 = new TestStruct3();
		myStruct3.b = 0x12345678;
		myStruct3.c = 0x76543210;
		p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TestStruct3)));
		Marshal.StructureToPtr(myStruct3, p, false);

		Type testType3 = typeof(TestStruct3);
		
		if(Marshal.ReadInt32(p, (int)Marshal.OffsetOf(testType3, "b")) != myStruct3.b)
			return 6;

		if (Marshal.ReadInt32(p, (int)Marshal.OffsetOf(testType3, "c")) != myStruct3.c) 
			return 7;

		Marshal.FreeHGlobal(p);
		
		///
		///	Also make sure OffsetOf returns the correct Exception.
		///
		try {
			Marshal.OffsetOf(testType3, "blah");
			return 8;
		}
		catch(ArgumentException e)  {
			/// Way to go :)
		}
		catch(Exception e) {
			return 9;
		}

		// test size of structs with objects
		if (Marshal.SizeOf (typeof (TestStruct4)) != IntPtr.Size)
			return 10;
		if (Marshal.SizeOf (typeof (TestStruct5)) != IntPtr.Size)
			return 11;
		if (Marshal.SizeOf (typeof (TestStruct6)) != IntPtr.Size)
			return 12;
		// a VARIANT is 
		if (Marshal.SizeOf (typeof (TestStruct7)) != 16)
			return 13;
		if (IsOSX () && IntPtr.Size == 4) {
			if (Marshal.SizeOf (typeof (TestStruct8)) != 12)
				return 14;
			if (Marshal.SizeOf (typeof (TestStruct10)) != 12)
				return 16;
		} else {
			if (Marshal.SizeOf (typeof (TestStruct8)) != 16)
				return 14;
			if (Marshal.SizeOf (typeof (TestStruct10)) != 16)
				return 16;
		}
		if (Marshal.SizeOf (typeof (TestStruct9)) != 12)
			return 15;
		if (Marshal.SizeOf (typeof (TestStruct11)) != 11)
			return 17;
		if (Marshal.SizeOf (typeof (TestStruct12)) != 6)
			return 18;
		if (Marshal.SizeOf (typeof (TestStruct13)) != 12)
			return 19;
		if (Marshal.SizeOf (typeof (TestStruct14)) != 12)
			return 20;
		return 0;
	}
Beispiel #21
0
 static TestStruct3 spill_struct(TestStruct3 regStruct, int value)
 {
     regStruct.c = value;
     return(regStruct);
 }
Beispiel #22
0
 static int spill_struct_void(TestStruct3 regStruct)
 {
     if (regStruct.c == 255)
         return 0;
     else
         return 7;
 }
Beispiel #23
0
        /// <summary>
        /// 对 <see cref="Cyjb.TypeExt.IsImplicitFrom"/> 方法进行测试的辅助方法。
        /// </summary>
        public void TestImplicitChangeTypeHelper(Func <object, Type, object> func)
        {
            object value = new object();

            #region 6.1.1 标识转换

            Assert.AreEqual(value, func(value, typeof(object)));
            value = true; Assert.AreEqual(value, func(value, typeof(bool)));
            value = 'A'; Assert.AreEqual(value, func(value, typeof(char)));
            value = (sbyte)10; Assert.AreEqual(value, func(value, typeof(sbyte)));
            value = (short)11; Assert.AreEqual(value, func(value, typeof(short)));
            value = (ushort)12; Assert.AreEqual(value, func(value, typeof(ushort)));
            value = (int)13; Assert.AreEqual(value, func(value, typeof(int)));
            value = (uint)14; Assert.AreEqual(value, func(value, typeof(uint)));
            value = (long)15; Assert.AreEqual(value, func(value, typeof(long)));
            value = (ulong)16; Assert.AreEqual(value, func(value, typeof(ulong)));
            value = (float)17; Assert.AreEqual(value, func(value, typeof(float)));
            value = (double)18; Assert.AreEqual(value, func(value, typeof(double)));
            value = (decimal)19; Assert.AreEqual(value, func(value, typeof(decimal)));
            value = new TestClass(); Assert.AreEqual(value, func(value, typeof(TestClass)));
            // 这里还有一点是 dynamic 和 object 是等效的,但由于在运行时
            // dynamic 和 object 没有区别(参见规范 4.7 节),
            // 因此在判断类型转换时完全不用考虑它。

            #endregion             // 6.1.1 标识转换

            #region 6.1.2 隐式数值转换

            Assert.AreEqual((short)10, func((sbyte)10, typeof(short)));
            Assert.AreEqual((int)11, func((sbyte)11, typeof(int)));
            Assert.AreEqual((long)12, func((sbyte)12, typeof(long)));
            Assert.AreEqual((float)13, func((sbyte)13, typeof(float)));
            Assert.AreEqual((double)14, func((sbyte)14, typeof(double)));
            Assert.AreEqual((decimal)15, func((sbyte)15, typeof(decimal)));
            Assert.AreEqual((short)10, func((byte)10, typeof(short)));
            Assert.AreEqual((ushort)11, func((byte)11, typeof(ushort)));
            Assert.AreEqual((int)12, func((byte)12, typeof(int)));
            Assert.AreEqual((uint)13, func((byte)13, typeof(uint)));
            Assert.AreEqual((long)14, func((byte)14, typeof(long)));
            Assert.AreEqual((ulong)15, func((byte)15, typeof(ulong)));
            Assert.AreEqual((float)16, func((byte)16, typeof(float)));
            Assert.AreEqual((double)17, func((byte)17, typeof(double)));
            Assert.AreEqual((decimal)18, func((byte)18, typeof(decimal)));
            Assert.AreEqual((int)12, func((short)12, typeof(int)));
            Assert.AreEqual((long)14, func((short)14, typeof(long)));
            Assert.AreEqual((float)16, func((short)16, typeof(float)));
            Assert.AreEqual((double)17, func((short)17, typeof(double)));
            Assert.AreEqual((decimal)18, func((short)18, typeof(decimal)));
            Assert.AreEqual((int)12, func((ushort)12, typeof(int)));
            Assert.AreEqual((uint)13, func((ushort)13, typeof(uint)));
            Assert.AreEqual((long)14, func((ushort)14, typeof(long)));
            Assert.AreEqual((ulong)15, func((ushort)15, typeof(ulong)));
            Assert.AreEqual((float)16, func((ushort)16, typeof(float)));
            Assert.AreEqual((double)17, func((ushort)17, typeof(double)));
            Assert.AreEqual((decimal)18, func((ushort)18, typeof(decimal)));
            Assert.AreEqual((long)14, func((int)14, typeof(long)));
            Assert.AreEqual((float)16, func((int)16, typeof(float)));
            Assert.AreEqual((double)17, func((int)17, typeof(double)));
            Assert.AreEqual((decimal)18, func((int)18, typeof(decimal)));
            Assert.AreEqual((long)14, func((uint)14, typeof(long)));
            Assert.AreEqual((ulong)15, func((uint)15, typeof(ulong)));
            Assert.AreEqual((float)16, func((uint)16, typeof(float)));
            Assert.AreEqual((double)17, func((uint)17, typeof(double)));
            Assert.AreEqual((decimal)18, func((uint)18, typeof(decimal)));
            Assert.AreEqual((float)16, func((long)16, typeof(float)));
            Assert.AreEqual((double)17, func((long)17, typeof(double)));
            Assert.AreEqual((decimal)18, func((long)18, typeof(decimal)));
            Assert.AreEqual((float)16, func((ulong)16, typeof(float)));
            Assert.AreEqual((double)17, func((ulong)17, typeof(double)));
            Assert.AreEqual((decimal)18, func((ulong)18, typeof(decimal)));
            Assert.AreEqual((ushort)11, func((char)11, typeof(ushort)));
            Assert.AreEqual((int)12, func((char)12, typeof(int)));
            Assert.AreEqual((uint)13, func((char)13, typeof(uint)));
            Assert.AreEqual((long)14, func((char)14, typeof(long)));
            Assert.AreEqual((ulong)15, func((char)15, typeof(ulong)));
            Assert.AreEqual((float)16, func((char)16, typeof(float)));
            Assert.AreEqual((double)17, func((char)17, typeof(double)));
            Assert.AreEqual((decimal)18, func((char)18, typeof(decimal)));
            Assert.AreEqual((double)17, func((float)17, typeof(double)));

            #endregion             // 6.1.2 隐式数值转换

            // 6.1.3 隐式枚举转换,针对的是十进制数字文本 0,不在考虑范围内。

            #region 6.1.4 可以为 null 的隐式转换

            // 从 S 到 T? 的隐式转换。
            Assert.AreEqual((int?)10, func((int)10, typeof(int?)));
            Assert.AreEqual((long?)10, func((int)10, typeof(long?)));
            // 从 S? 到 T? 的隐式转换。
            Assert.AreEqual((int?)10, func((int?)10, typeof(int?)));
            Assert.AreEqual((long?)10, func((int?)10, typeof(long?)));
            Assert.AreEqual((long?)null, func((int?)null, typeof(long?)));

            #endregion             // 6.1.4 可以为 null 的隐式转换

            // 6.1.5 null 文本转换,不在考虑范围内。

            #region 6.1.6 隐式引用转换

            // 6.1.6.1 从任何 reference-type 到 object (和 dynamic)。
            value = "abc"; Assert.AreEqual((object)value, func(value, typeof(object)));
            value = new TestClass(); Assert.AreEqual((object)value, func(value, typeof(object)));
            // 6.1.6.2 从任何 class-type S 到任何 class-type T(前提是 S 是从 T 派生的)。
            value = new TestClass2(); Assert.AreEqual((TestClass)value, func(value, typeof(TestClass)));
            // 6.1.6.3 从任何 class-type S 到任何 interface-type T(前提是 S 实现了 T)。
            value = new List <int>(); Assert.AreEqual((IList <int>)value, func(value, typeof(IList <int>)));
            // 6.1.6.4 从任何 interface-type S 到任何 interface-type T(前提是 S 是从 T 派生的)。
            value = new List <int>(); Assert.AreEqual((IList)value, func(value, typeof(IList)));
            // 6.1.6.5 从元素类型为 SE 的 array-type S 到元素类型为 TE 的 array-type T(前提是以下所列条件均成立):
            // o S 和 T 只有元素类型不同。换言之,S 和 T 具有相同的维数。
            // o SE 和 TE 都是 reference-type。
            // o 存在从 SE 到 TE 的隐式引用转换。
            value = new string[0]; Assert.AreEqual((object[])value, func(value, typeof(object[])));
            value = new TestClass2[0]; Assert.AreEqual((TestClass[])value, func(value, typeof(TestClass[])));
            value = new List <int> [0]; Assert.AreEqual((IList[])value, func(value, typeof(IList[])));
            value = new List <string> [0]; Assert.AreEqual(value, func(value, typeof(IEnumerable <object>[])));
            // 6.1.6.6 从任何 array-type 到 System.Array 及其实现的接口。
            value = new int[0]; Assert.AreEqual((Array)value, func(value, typeof(Array)));
            value = new object[0]; Assert.AreEqual((Array)value, func(value, typeof(Array)));
            // 6.1.6.7 从一维数组类型 S[] 到 System.Collections.Generic.IList<T> 及其基接口
            // (前提是存在从 S 到 T 的隐式标识或引用转换)。
            value = new int[0]; Assert.AreEqual((IList <int>)value, func(value, typeof(IList <int>)));
            value = new TestClass[0][][];
            Assert.AreEqual((IList <IList <TestClass>[]>)value, func(value, typeof(IList <IList <TestClass>[]>)));
            // 6.1.6.8 从任何 delegate-type 到 System.Delegate 及其实现的接口。
            value = new Func <int>(TestMethod); Assert.AreEqual((Delegate)value, func((Delegate)value, typeof(Delegate)));
            // 6.1.6.9 从 null 文本到任何 reference-type,不在考虑范围内。
            // 6.1.6.10 从任何 reference-type 到 reference-type T
            // (前提是它具有到 reference-type T0 的隐式标识或引用转换,且 T0 具有到 T 的标识转换)。
            // 此条规则也可以不考虑。
            // 6.1.6.11 从任何 reference-type 到接口或委托类型 T
            // (前提是它具有到接口或委托类型 T0 的隐式标识或引用转换,且 T0 可变化转换为T)。
            // 这里的变化转换在规范的 13.1.3.2 节,就是泛型的协变和逆变。
            // 协变。
            value = Enumerable.Empty <string>();
            Assert.AreEqual((IEnumerable <object>)value, func(value, typeof(IEnumerable <object>)));
            value = Enumerable.Empty <IEqualityComparer <object>[]>();
            Assert.AreEqual((IEnumerable <IEqualityComparer <string>[]>)value, func(value, typeof(IEnumerable <IEqualityComparer <string>[]>)));
            value = Enumerable.Empty <object[][]>();
            Assert.AreEqual((IEnumerable <IList <IList <object> > >)value, func(value, typeof(IEnumerable <IList <IList <object> > >)));
            // 逆变。
            value = EqualityComparer <object> .Default;
            Assert.AreEqual((IEqualityComparer <string>)value, func(value, typeof(IEqualityComparer <string>)));
            value = EqualityComparer <IEnumerable <object>[]> .Default;
            Assert.AreEqual((IEqualityComparer <IEnumerable <string>[]>)value, func(value, typeof(IEqualityComparer <IEnumerable <string>[]>)));
            value = EqualityComparer <IList <TestClass[]> > .Default;
            Assert.AreEqual((IEqualityComparer <TestClass2[][]>)value, func(value, typeof(IEqualityComparer <TestClass2[][]>)));
            // 6.1.6.12 涉及已知为引用类型的类型参数的隐式转换。这个转换是针对类型参数 T 的,因此同样不做考虑。

            #endregion             // 6.1.6 隐式引用转换

            #region 6.1.7 装箱转换

            // 从 non-nullable-value-type 到 object。
            value = (uint)10; Assert.AreEqual((object)value, func(value, typeof(object)));
            value = new TestStruct(); Assert.AreEqual((object)value, func(value, typeof(object)));
            // 从 non-nullable-value-type 到 System.ValueType。
            value = 10; Assert.AreEqual((ValueType)value, func(value, typeof(ValueType)));
            value = new TestStruct2(); Assert.AreEqual((ValueType)value, func(value, typeof(ValueType)));
            // 从 non-nullable-value-type 到其实现的接口。
            value = 10; Assert.AreEqual((IComparable <int>)value, func(value, typeof(IComparable <int>)));
            value = new TestStruct4(); Assert.AreEqual((IEnumerable <string>)value, func(value, typeof(IEnumerable <string>)));
            // 从 enum-type 转换为 System.Enum 类型。
            value = Tristate.True; Assert.AreEqual((Enum)value, func(value, typeof(Enum)));
            // 从 nullable-type 到引用类型的装箱转换,如果存在从对应的 non-nullable-value-type 到该引用类型的装箱转换。
            value = (uint?)10; Assert.AreEqual((object)value, func(value, typeof(object)));
            value = (int?)11; Assert.AreEqual((ValueType)value, func(value, typeof(ValueType)));
            value = (int?)null; Assert.AreEqual((ValueType)value, func(value, typeof(ValueType)));
            value = (int?)12; Assert.AreEqual((IComparable <int>)value, func(value, typeof(IComparable <int>)));
            value = (Tristate?)Tristate.True; Assert.AreEqual((Enum)value, func(value, typeof(Enum)));
            // 如果值类型具有到接口或委托类型 I0 的装箱转换,且 I0 变化转换为接口类型 I,则值类型具有到 I 的装箱转换。
            value = new TestStruct4(); Assert.AreEqual((IEnumerable <object>)value, func(value, typeof(IEnumerable <object>)));
            value = (TestStruct4?)new TestStruct4(); Assert.AreEqual((IEnumerable <object>)value, func(value, typeof(IEnumerable <object>)));
            value = (TestStruct4?)null; Assert.AreEqual((IEnumerable <object>)value, func(value, typeof(IEnumerable <object>)));

            #endregion             // 6.1.7 装箱转换

            // 6.1.8 隐式动态转换、6.1.9 隐式常量表达式转换、6.1.10 涉及类型形参的隐式转换,不在考虑范围内。

            #region 6.1.11 用户定义的隐式转换

            value = new TestStruct2();
            object expectedValue = (TestStruct) new TestStruct2();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct)));
            value         = new TestStruct2();
            expectedValue = (TestStruct?)new TestStruct2();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct?)));
            value         = (TestStruct2?)new TestStruct2();
            expectedValue = (TestStruct?)(TestStruct2?)new TestStruct2();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct?)));
            value = (TestStruct2?)null;
            Assert.AreEqual((TestStruct?)value, func(value, typeof(TestStruct?)));
            value         = new TestStruct3();
            expectedValue = (TestStruct) new TestStruct3();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct)));
            value         = new TestStruct3();
            expectedValue = (TestStruct?)new TestStruct3();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct?)));
            value         = (TestStruct3?)new TestStruct3();
            expectedValue = (TestStruct?)(TestStruct3?)new TestStruct3();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct?)));
            value         = (TestStruct3?)null; Assert.AreEqual(value, func(value, typeof(TestStruct?)));
            value         = new TestStruct5();
            expectedValue = (TestStruct?)new TestStruct5();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct?)));
            value         = new TestStruct6();
            expectedValue = (TestStruct) new TestStruct6();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct)));
            value         = (TestStruct6?)new TestStruct6();
            expectedValue = (TestStruct)(TestStruct6?)new TestStruct6();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct)));
            value         = new TestStruct6();
            expectedValue = (TestStruct?)new TestStruct6();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct?)));
            value         = (TestStruct6?)new TestStruct6();
            expectedValue = (TestStruct?)(TestStruct6?)new TestStruct6();
            Assert.AreEqual(expectedValue, func(value, typeof(TestStruct?)));
            value         = (TestStruct6?)null; Assert.AreEqual(value, func(value, typeof(TestStruct?)));
            value         = new TestClass();
            expectedValue = (int)new TestClass();
            Assert.AreEqual(expectedValue, func(value, typeof(int)));
            value         = new TestClass2();
            expectedValue = (int)new TestClass2();
            Assert.AreEqual(expectedValue, func(value, typeof(int)));
            value         = new TestClass2();
            expectedValue = (long)new TestClass2();
            Assert.AreEqual(expectedValue, func(value, typeof(long)));
            value         = new TestClass2();
            expectedValue = (bool)new TestClass2();
            Assert.AreEqual(expectedValue, func(value, typeof(bool)));
            value         = new TestClass13();
            expectedValue = (Enum) new TestClass13();
            Assert.AreEqual(expectedValue, func(value, typeof(Enum)));
            value         = new TestClass12();
            expectedValue = (int?)new TestClass12();
            Assert.AreEqual(expectedValue, func(value, typeof(int?)));
            value         = new TestClass8();
            expectedValue = (TestClass6) new TestClass8();
            Assert.AreEqual(expectedValue, func(value, typeof(TestClass6)));
            value         = new TestClass6();
            expectedValue = (TestClass7) new TestClass6();
            Assert.AreEqual(expectedValue, func(value, typeof(TestClass7)));
            value         = 10;
            expectedValue = (TestClass6)10;
            Assert.AreEqual(expectedValue, func(value, typeof(TestClass6)));
            value         = new TestClass();
            expectedValue = (long)new TestClass();
            Assert.AreEqual(expectedValue, func(value, typeof(long)));
            value         = new TestClass();
            expectedValue = (decimal) new TestClass();
            Assert.AreEqual(expectedValue, func(value, typeof(decimal)));
            value         = new TestClass2();
            expectedValue = (decimal) new TestClass2();
            Assert.AreEqual(expectedValue, func(value, typeof(decimal)));
            value         = (short)10;
            expectedValue = (TestClass6)(short)10;
            Assert.AreEqual(expectedValue, func(value, typeof(TestClass6)));
            value         = new TestClass6();
            expectedValue = (long)new TestClass6();
            Assert.AreEqual(expectedValue, func(value, typeof(long)));

            #endregion             // 6.1.11 用户定义的隐式转换
        }