public void Sr_ReadArray() { var rdr = new LeImageReader(new byte[] { 0x4A, 0x4B, // signature 0x08, 0x00, 0x00, 0x00, // pointer to directory 0xFF, 0xFF, // padding 0x10, 0, // Directory slot 0 0x13, 0, // Directory slot 1 0x16, 0, // Directory slot 2 0x19, 0, // Directory slot 3 0x61, 0x62, 0x00, 0x63, 0x64, 0x00, 0x65, 0x66, 0x00, 0x65, 0x78, 0x00, }); var test = new TestStruct6(); var sr = new StructureReader(test); sr.Read(rdr); Assert.IsNotNull(test.directory); Assert.IsNotNull(test.directory.sections); Assert.AreEqual(4, test.directory.sections.Length); Assert.AreEqual("ab", test.directory.sections[0].name); Assert.AreEqual("cd", test.directory.sections[1].name); Assert.AreEqual("ef", test.directory.sections[2].name); Assert.AreEqual("ex", test.directory.sections[3].name); }
public static int test_0_ia64_struct6() { TestStruct6 s = new TestStruct6(); s.d1 = 6.0; s.d2 = -6.0; TestStruct6 s2 = mono_test_marshal_ia64_pass_return_struct6(1.0, 2.0, s, 3, 4.0, 5.0); return((s2.d1 == 12.0 && s2.d2 == 3.0) ? 0 : 1); }
public static extern TestStruct6 mono_test_marshal_ia64_pass_return_struct6(double d1, double d2, TestStruct6 s, int i, double f3, double f4);
public static int test_0_ia64_struct6() { TestStruct6 s = new TestStruct6 (); s.d1 = 6.0; s.d2 = -6.0; TestStruct6 s2 = mono_test_marshal_ia64_pass_return_struct6 (1.0, 2.0, s, 3, 4.0, 5.0); return (s2.d1 == 12.0 && s2.d2 == 3.0) ? 0 : 1; }
static void Main(string[] args) { Label.Checkpoint("init", "bp_test", (Object context) => { Context Context = (Context)context; Context.PrepareStart(@"__FILE__:__LINE__"); Context.AddBreakpoint(@"__FILE__:__LINE__", "bp"); Context.AddBreakpoint(@"__FILE__:__LINE__", "bp2"); Context.AddBreakpoint(@"__FILE__:__LINE__", "bp3"); Context.AddBreakpoint(@"__FILE__:__LINE__", "bp4"); Context.AddBreakpoint(@"__FILE__:__LINE__", "bp5"); Context.AddBreakpoint(@"__FILE__:__LINE__", "bp_func"); Context.AddBreakpoint(@"__FILE__:__LINE__", "bp_getter"); Context.SetBreakpoints(@"__FILE__:__LINE__"); Context.PrepareEnd(@"__FILE__:__LINE__"); Context.WasEntryPointHit(@"__FILE__:__LINE__"); Context.Continue(@"__FILE__:__LINE__"); }); int i = 2; string test_string = "test"; Console.WriteLine("i = " + i.ToString()); Console.WriteLine(test_string); Console.WriteLine("A breakpoint \"bp\" is set on this line"); Label.Breakpoint("bp"); Label.Checkpoint("bp_test", "bp_func_test", (Object context) => { Context Context = (Context)context; Context.WasBreakpointHit(@"__FILE__:__LINE__", "bp"); Int64 frameId = Context.DetectFrameId(@"__FILE__:__LINE__", "bp"); Context.CheckVariablesCount(@"__FILE__:__LINE__", frameId, "Locals", 7); int variablesReference = Context.GetVariablesReference(@"__FILE__:__LINE__", frameId, "Locals"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference, "string[]", "args", "{string[0]}"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference, "int", "i", "2"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference, "string", "test_string", "\"test\""); Assert.True(Context.SetVariable(@"__FILE__:__LINE__", variablesReference, "i", "5").Success, @"__FILE__:__LINE__"); Assert.False(Context.SetVariable(@"__FILE__:__LINE__", variablesReference, "i", "\"string\"").Success, @"__FILE__:__LINE__"); Assert.True(Context.SetVariable(@"__FILE__:__LINE__", variablesReference, "test_string", "\"changed_String\"").Success, @"__FILE__:__LINE__"); Assert.False(Context.SetVariable(@"__FILE__:__LINE__", variablesReference, "test_string", "5").Success, @"__FILE__:__LINE__"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference, "int", "i", "5"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference, "string", "test_string", "\"changed_String\""); Context.Continue(@"__FILE__:__LINE__"); }); TestFunction(10); TestStruct4 ts4 = new TestStruct4(); i++; Label.Breakpoint("bp2"); Label.Checkpoint("test_debugger_browsable_state", "test_NotifyOfCrossThreadDependency", (Object context) => { Context Context = (Context)context; Context.WasBreakpointHit(@"__FILE__:__LINE__", "bp2"); Int64 frameId = Context.DetectFrameId(@"__FILE__:__LINE__", "bp2"); int variablesReference_Locals = Context.GetVariablesReference(@"__FILE__:__LINE__", frameId, "Locals"); int variablesReference_ts4 = Context.GetChildVariablesReference(@"__FILE__:__LINE__", variablesReference_Locals, "ts4"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts4, "int", "val1", "666"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts4, "int", "val3", "888"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts4, "int", 0, "666"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts4, "int", 1, "888"); Context.Continue(@"__FILE__:__LINE__"); }); TestStruct5 ts5 = new TestStruct5(); // part of NotifyOfCrossThreadDependency test, no active evaluation here for sure System.Diagnostics.Debugger.NotifyOfCrossThreadDependency(); i++; Label.Breakpoint("bp3"); Label.Checkpoint("test_NotifyOfCrossThreadDependency", "test_eval_timeout", (Object context) => { Context Context = (Context)context; Context.WasBreakpointHit(@"__FILE__:__LINE__", "bp3"); Int64 frameId = Context.DetectFrameId(@"__FILE__:__LINE__", "bp3"); int variablesReference_Locals = Context.GetVariablesReference(@"__FILE__:__LINE__", frameId, "Locals"); int variablesReference_ts5 = Context.GetChildVariablesReference(@"__FILE__:__LINE__", variablesReference_Locals, "ts5"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts5, "int", "val1", "111"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts5, "", "val2", "<error>"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts5, "string", "val3", "\"text_333\""); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts5, "", "val4", "<error>"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts5, "float", "val5", "555.5"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts5, "int", 0, "111"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts5, "", 1, "<error>"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts5, "string", 2, "\"text_333\""); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts5, "", 3, "<error>"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts5, "float", 4, "555.5"); Context.Continue(@"__FILE__:__LINE__"); }); TestStruct6 ts6 = new TestStruct6(); i++; Label.Breakpoint("bp4"); Label.Checkpoint("test_eval_timeout", "test_eval_exception", (Object context) => { Context Context = (Context)context; Context.WasBreakpointHit(@"__FILE__:__LINE__", "bp4"); Int64 frameId = Context.DetectFrameId(@"__FILE__:__LINE__", "bp4"); int variablesReference_Locals = Context.GetVariablesReference(@"__FILE__:__LINE__", frameId, "Locals"); int variablesReference_ts6 = Context.GetChildVariablesReference(@"__FILE__:__LINE__", variablesReference_Locals, "ts6"); var task = System.Threading.Tasks.Task.Run(() => { Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts6, "int", "val1", "123"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts6, "", "val2", "<error>"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts6, "string", "val3", "\"text_123\""); }); // we have 5 seconds evaluation timeout by default, wait 20 seconds (5 seconds eval timeout * 3 eval requests + 5 seconds reserve) if (!task.Wait(TimeSpan.FromSeconds(20))) { throw new DebuggerTimedOut(@"__FILE__:__LINE__"); } task = System.Threading.Tasks.Task.Run(() => { Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts6, "int", 0, "123"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts6, "", 1, "<error>"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts6, "string", 2, "\"text_123\""); }); // we have 5 seconds evaluation timeout by default, wait 20 seconds (5 seconds eval timeout * 3 eval requests + 5 seconds reserve) if (!task.Wait(TimeSpan.FromSeconds(20))) { throw new DebuggerTimedOut(@"__FILE__:__LINE__"); } Context.Continue(@"__FILE__:__LINE__"); }); TestStruct7 ts7 = new TestStruct7(); i++; Label.Breakpoint("bp5"); Label.Checkpoint("test_eval_exception", "finish", (Object context) => { Context Context = (Context)context; Context.WasBreakpointHit(@"__FILE__:__LINE__", "bp5"); Int64 frameId = Context.DetectFrameId(@"__FILE__:__LINE__", "bp5"); int variablesReference_Locals = Context.GetVariablesReference(@"__FILE__:__LINE__", frameId, "Locals"); int variablesReference_ts7 = Context.GetChildVariablesReference(@"__FILE__:__LINE__", variablesReference_Locals, "ts7"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts7, "int", "val1", "567"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts7, "int", "val2", "777"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts7, "System.DivideByZeroException", "val3", "{System.DivideByZeroException}"); Context.EvalVariable(@"__FILE__:__LINE__", variablesReference_ts7, "string", "val4", "\"text_567\""); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts7, "int", 0, "567"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts7, "int", 1, "777"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts7, "System.DivideByZeroException", 2, "{System.DivideByZeroException}"); Context.EvalVariableByIndex(@"__FILE__:__LINE__", variablesReference_ts7, "string", 3, "\"text_567\""); Context.Continue(@"__FILE__:__LINE__"); }); Label.Checkpoint("finish", "", (Object context) => { Context Context = (Context)context; Context.WasExit(@"__FILE__:__LINE__"); Context.DebuggerExit(@"__FILE__:__LINE__"); }); }
/// <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 用户定义的隐式转换 }