public void GenericMethodCall_WhenSomeNotInferredTypeArguments_ShouldExplicitlySpecifyTypeArguments() { Assert.AreEqual( @"() => StaticTestClass.IsType<int, int>(3)", ExpressionStringify.With(explicitMethodTypeArgs: true).ToCode(() => StaticTestClass.IsType <int, int>(3)) ); }
public void CannotInferOneParam() { Assert.AreEqual( @"() => StaticTestClass.IsType<int, int>(3)", ExpressionToCode.ToCode(() => StaticTestClass.IsType <int, int>(3)) ); }
public void StraightforwardInference() { Assert.AreEqual( @"() => StaticTestClass.Identity(3)", ExpressionToCode.ToCode(() => StaticTestClass.Identity(3)) ); }
public void AvoidsImplicitBoxingWhenTargetTypeIsAGenericArgument() { Assert.AreEqual( @"() => StaticTestClass.TwoArgsTwoGeneric(3, new object())", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsTwoGeneric(3, new object())) ); }
public void GenericMethodCall_WhenSomeNotInferredTypeArguments_ShouldExplicitlySpecifyTypeArguments() => Assert.Equal( @"() => StaticTestClass.IsType<int, int>(3)", ExpressionToCodeConfiguration.DefaultCodeGenConfiguration.WithAlwaysUseExplicitTypeArguments(true) .WithObjectStringifier(ObjectStringify.Default) .GetExpressionToCode() .ToCode(() => StaticTestClass.IsType <int, int>(3)) );
public void AvoidsImplicitCastWhenTargetTypeIsAGenericArgument() { var x = 37; var y = 42.0; Assert.Equal( @"() => StaticTestClass.TwoArgsTwoGeneric(x, y)", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsTwoGeneric(x, y)) ); }
public void CanInferDirect() { Assert.AreEqual( @"() => StaticTestClass.TwoArgsOneGeneric(3, 3)", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsOneGeneric(3, 3)) ); Assert.AreEqual( @"() => StaticTestClass.TwoArgsOneGeneric(3, ""3"")", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsOneGeneric(3, "3")) ); }
public void CannotInferWithoutTParam() { Assert.AreEqual( @"() => StaticTestClass.TEqualsInt<int>(3)", ExpressionToCode.ToCode(() => StaticTestClass.TEqualsInt <int>(3)) ); Assert.AreEqual( @"() => StaticTestClass.TEqualsInt<string>(3)", ExpressionToCode.ToCode(() => StaticTestClass.TEqualsInt <string>(3)) ); }
public void CanInferTwoArg() { Assert.AreEqual( @"() => StaticTestClass.TwoArgsTwoGeneric(3, 3)", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsTwoGeneric(3, 3)) ); Assert.AreEqual( @"() => StaticTestClass.TwoArgsTwoGeneric((object)3, new object())", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsTwoGeneric(3, new object())) ); int x = 37; double y = 42.0; Assert.AreEqual( @"() => StaticTestClass.TwoArgsTwoGeneric((double)x, y)", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsTwoGeneric(x, y)) ); }
public void CanInferTwoArg() { Assert.Equal( @"() => StaticTestClass.TwoArgsTwoGeneric(3, 3)", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsTwoGeneric(3, 3)) ); Assert.Equal( @"() => StaticTestClass.TwoArgsTwoGeneric(3, new object())", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsTwoGeneric(3, new object())) ); var x = 37; var y = 42.0; Assert.Equal( @"() => StaticTestClass.TwoArgsTwoGeneric(x, y)", ExpressionToCode.ToCode(() => StaticTestClass.TwoArgsTwoGeneric(x, y)) ); }
public void TypeParameters() { Assert.AreEqual(1337, StaticTestClass.Consume(12)); Assert.AreEqual(42, StaticTestClass.Consume <int>(12)); Assert.AreEqual(42, StaticTestClass.Consume('a')); Assert.AreEqual(42, StaticTestClass.IndirectConsume(12)); Assert.AreEqual( @"() => 1337 == StaticTestClass.Consume(12)", ExpressionToCode.ToCode(() => 1337 == StaticTestClass.Consume(12)) ); Assert.AreEqual( @"() => 42 == StaticTestClass.Consume('a')", ExpressionToCode.ToCode(() => 42 == StaticTestClass.Consume('a')) ); Assert.AreEqual( @"() => 42 == StaticTestClass.IndirectConsume(12)", ExpressionToCode.ToCode(() => 42 == StaticTestClass.IndirectConsume(12)) ); Assert.AreEqual( @"() => 42 == StaticTestClass.Consume<int>(12)", ExpressionToCode.ToCode(() => 42 == StaticTestClass.Consume <int>(12)) ); //should not remove type parameters where this would cause ambiguity due to overloads! }