public static void ConvertTo_WithContext() { RemoteExecutor.Invoke(() => { CultureInfo.CurrentCulture = new CultureInfo("pl-PL"); DateTimeFormatInfo formatInfo = (DateTimeFormatInfo)CultureInfo.CurrentCulture.GetFormat(typeof(DateTimeFormatInfo)); string formatWithTime = formatInfo.ShortDatePattern + " " + formatInfo.ShortTimePattern; string format = formatInfo.ShortDatePattern; DateTime testDateAndTime = new DateTime(1998, 12, 5, 22, 30, 30); ConstructorInfo ctor = typeof(DateTime).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) }); InstanceDescriptor descriptor = new InstanceDescriptor(ctor, new object[] { testDateAndTime.Year, testDateAndTime.Month, testDateAndTime.Day, testDateAndTime.Hour, testDateAndTime.Minute, testDateAndTime.Second, testDateAndTime.Millisecond }); ConvertTo_WithContext(new object[5, 3] { { DateTimeConverterTests.s_testDate, DateTimeConverterTests.s_testDate.ToString(format, CultureInfo.CurrentCulture), null }, { testDateAndTime, testDateAndTime.ToString(formatWithTime, CultureInfo.CurrentCulture), null }, { DateTime.MinValue, string.Empty, null }, { DateTimeConverterTests.s_testDate, "1998-12-05", CultureInfo.InvariantCulture }, { testDateAndTime, "12/05/1998 22:30:30", CultureInfo.InvariantCulture } }, DateTimeConverterTests.s_converter); object describedInstanceNoCulture = s_converter.ConvertTo(TypeConverterTests.s_context, null, testDateAndTime, descriptor.GetType()); describedInstanceNoCulture = ((InstanceDescriptor)describedInstanceNoCulture).Invoke(); object describedInstanceCulture = s_converter.ConvertTo(TypeConverterTests.s_context, CultureInfo.InvariantCulture, testDateAndTime, descriptor.GetType()); describedInstanceCulture = ((InstanceDescriptor)describedInstanceCulture).Invoke(); Assert.Equal(testDateAndTime, describedInstanceNoCulture); Assert.Equal(testDateAndTime, describedInstanceCulture); return(RemoteExecutor.SuccessExitCode); }).Dispose(); }