Created
May 2, 2022 00:59
-
-
Save searope/3798a3faf85dd6940d15b3accce202a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void PrintTypes(LambdaExpression expr) | |
| { | |
| Console.WriteLine(expr); | |
| ConstantExpression cexpr = expr.Body as ConstantExpression; | |
| if (cexpr != null) | |
| { | |
| Console.WriteLine("\t{0}", cexpr.Type); | |
| return; | |
| } | |
| BinaryExpression bexpr = expr.Body as BinaryExpression; | |
| if (bexpr != null) | |
| { | |
| Console.WriteLine("\t{0}", bexpr.Left.Type); | |
| Console.WriteLine("\t{0}", bexpr.Right.Type); | |
| return; | |
| } | |
| return; | |
| } | |
| PrintTypes((Expression<Func<bool>>)(() => null == null)); // constant folded directly to bool | |
| PrintTypes((Expression<Func<bool>>)(() => null != null)); // constant folded directly to bool | |
| PrintTypes((Expression<Func<bool>>)(() => null < null)); | |
| PrintTypes((Expression<Func<bool>>)(() => null <= null)); | |
| PrintTypes((Expression<Func<bool>>)(() => null > null)); | |
| PrintTypes((Expression<Func<bool>>)(() => null >= null)); | |
| /* | |
| Outputs: | |
| () => True | |
| System.Boolean | |
| () => False | |
| System.Boolean | |
| () => (null < null) | |
| System.Nullable`1[System.Int32] | |
| System.Nullable`1[System.Int32] | |
| () => (null <= null) | |
| System.Nullable`1[System.Int32] | |
| System.Nullable`1[System.Int32] | |
| () => (null > null) | |
| System.Nullable`1[System.Int32] | |
| System.Nullable`1[System.Int32] | |
| () => (null >= null) | |
| System.Nullable`1[System.Int32] | |
| System.Nullable`1[System.Int32] | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment