public void HasExactType() { var opt = new TypingTestExpressionOptimizer(); foreach (var e in new Expression[] { Expression.Constant(42), Expression.Default(typeof(int)), Expression.NewArrayBounds(typeof(int), Expression.Constant(1)), Expression.NewArrayInit(typeof(int), Expression.Constant(1)), Expression.New(typeof(string).GetConstructor(new[] { typeof(char), typeof(int) }), Expression.Constant('*'), Expression.Constant(1)), Expression.ListInit(Expression.New(typeof(List <int>).GetConstructor(Type.EmptyTypes)), Expression.ElementInit(typeof(List <int>).GetMethod(nameof(List <int> .Add), new[] { typeof(int) }), Expression.Constant(1))), Expression.MemberInit(Expression.New(typeof(StrongBox <int>).GetConstructor(Type.EmptyTypes)), Expression.Bind(typeof(StrongBox <int>).GetField(nameof(StrongBox <int> .Value)), Expression.Constant(1))), Expression.IsFalse(Expression.Constant(true)), Expression.IsTrue(Expression.Constant(true)), Expression.TypeEqual(Expression.Constant(42), typeof(int)), Expression.TypeIs(Expression.Constant(42), typeof(int)), Expression.Call(Expression.Constant(""), typeof(string).GetMethod(nameof(string.ToUpper), Type.EmptyTypes)), Expression.Convert(Expression.Default(typeof(object)), typeof(int)), }) { Assert.IsTrue(opt.HasExactType(e), e.ToString()); } foreach (var e in new Expression[] { Expression.Constant(null), Expression.Constant("", typeof(object)), Expression.Default(typeof(int?)), Expression.Default(typeof(string)), Expression.Convert(Expression.Default(typeof(string)), typeof(object)), Expression.Convert(Expression.Default(typeof(object)), typeof(int?)), }) { Assert.IsFalse(opt.HasExactType(e), e.ToString()); } }