Beispiel #1
0
        public void FindTryParseMethod_ReturnsTheExpectedTryParseMethodWithInvariantCultureDateType(Type @type)
        {
            var methodFound = TryParseMethodCache.FindTryParseMethod(@type);

            Assert.NotNull(methodFound);

            var call       = methodFound !(Expression.Variable(type, "parsedValue"));
            var parameters = call.Method.GetParameters();

            if (@type == typeof(TimeSpan))
            {
                Assert.Equal(3, parameters.Length);
                Assert.Equal(typeof(string), parameters[0].ParameterType);
                Assert.Equal(typeof(IFormatProvider), parameters[1].ParameterType);
                Assert.True(parameters[2].IsOut);
            }
            else
            {
                Assert.Equal(4, parameters.Length);
                Assert.Equal(typeof(string), parameters[0].ParameterType);
                Assert.Equal(typeof(IFormatProvider), parameters[1].ParameterType);
                Assert.Equal(typeof(DateTimeStyles), parameters[2].ParameterType);
                Assert.True(parameters[3].IsOut);
            }
        }
Beispiel #2
0
        public void FindTryParseMethod_ReturnsTheExpectedTryParseMethodWithInvariantCultureCustomType(Type @type)
        {
            var methodFound = TryParseMethodCache.FindTryParseMethod(@type);

            Assert.NotNull(methodFound);

            var call       = methodFound !(Expression.Variable(type, "parsedValue"));
            var parameters = call.Method.GetParameters();

            Assert.Equal(3, parameters.Length);
            Assert.Equal(typeof(string), parameters[0].ParameterType);
            Assert.Equal(typeof(IFormatProvider), parameters[1].ParameterType);
            Assert.True(parameters[2].IsOut);
            Assert.True(((call.Arguments[1] as ConstantExpression) !.Value as CultureInfo) !.Equals(CultureInfo.InvariantCulture));
        }