Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ConstantCheck.cs
Go to the documentation of this file.
2
4
5internal static class ConstantCheck
6{
7 internal static bool IsNull(Expression e)
8 {
9 return e.NodeType switch
10 {
11 ExpressionType.Constant => ((ConstantExpression)e).Value == null,
12 ExpressionType.Default => e.Type.IsNullableOrReferenceType(),
13 _ => false,
14 };
15 }
16
18 {
19 return AnalyzeTypeIs(typeIs.Expression, typeIs.TypeOperand);
20 }
21
22 private static AnalyzeTypeIsResult AnalyzeTypeIs(Expression operand, Type testType)
23 {
24 Type type = operand.Type;
25 if (type == typeof(void))
26 {
27 if (!(testType == typeof(void)))
28 {
29 return AnalyzeTypeIsResult.KnownFalse;
30 }
31 return AnalyzeTypeIsResult.KnownTrue;
32 }
33 if (testType == typeof(void) || testType.IsPointer)
34 {
35 return AnalyzeTypeIsResult.KnownFalse;
36 }
37 Type nonNullableType = type.GetNonNullableType();
38 Type nonNullableType2 = testType.GetNonNullableType();
39 if (nonNullableType2.IsAssignableFrom(nonNullableType))
40 {
41 if (type.IsValueType && !type.IsNullableType())
42 {
43 return AnalyzeTypeIsResult.KnownTrue;
44 }
45 return AnalyzeTypeIsResult.KnownAssignable;
46 }
47 return AnalyzeTypeIsResult.Unknown;
48 }
49}
static AnalyzeTypeIsResult AnalyzeTypeIs(TypeBinaryExpression typeIs)
static bool IsNull(Expression e)
static AnalyzeTypeIsResult AnalyzeTypeIs(Expression operand, Type testType)
virtual bool IsAssignableFrom([NotNullWhen(true)] Type? c)
Definition Type.cs:1561
bool IsPointer
Definition Type.cs:75