mscorlib(4.0.0.0) API with additions
SwitchExpression.cs
3 using System.Diagnostics;
4 using System.Dynamic.Utils;
5 using System.Reflection;
6 
8 {
10  [DebuggerTypeProxy(typeof(SwitchExpressionProxy))]
11  [global::__DynamicallyInvokable]
12  public sealed class SwitchExpression : Expression
13  {
14  private readonly Type _type;
15 
16  private readonly Expression _switchValue;
17 
18  private readonly ReadOnlyCollection<SwitchCase> _cases;
19 
20  private readonly Expression _defaultBody;
21 
22  private readonly MethodInfo _comparison;
23 
26  [global::__DynamicallyInvokable]
27  public sealed override Type Type
28  {
29  [global::__DynamicallyInvokable]
30  get
31  {
32  return _type;
33  }
34  }
35 
38  [global::__DynamicallyInvokable]
39  public sealed override ExpressionType NodeType
40  {
41  [global::__DynamicallyInvokable]
42  get
43  {
44  return ExpressionType.Switch;
45  }
46  }
47 
50  [global::__DynamicallyInvokable]
51  public Expression SwitchValue
52  {
53  [global::__DynamicallyInvokable]
54  get
55  {
56  return _switchValue;
57  }
58  }
59 
62  [global::__DynamicallyInvokable]
64  {
65  [global::__DynamicallyInvokable]
66  get
67  {
68  return _cases;
69  }
70  }
71 
74  [global::__DynamicallyInvokable]
75  public Expression DefaultBody
76  {
77  [global::__DynamicallyInvokable]
78  get
79  {
80  return _defaultBody;
81  }
82  }
83 
86  [global::__DynamicallyInvokable]
87  public MethodInfo Comparison
88  {
89  [global::__DynamicallyInvokable]
90  get
91  {
92  return _comparison;
93  }
94  }
95 
96  internal bool IsLifted
97  {
98  get
99  {
100  if (_switchValue.Type.IsNullableType())
101  {
102  if (!(_comparison == null))
103  {
104  return !TypeUtils.AreEquivalent(_switchValue.Type, _comparison.GetParametersCached()[0].ParameterType.GetNonRefType());
105  }
106  return true;
107  }
108  return false;
109  }
110  }
111 
112  internal SwitchExpression(Type type, Expression switchValue, Expression defaultBody, MethodInfo comparison, ReadOnlyCollection<SwitchCase> cases)
113  {
114  _type = type;
115  _switchValue = switchValue;
116  _defaultBody = defaultBody;
117  _comparison = comparison;
118  _cases = cases;
119  }
120 
121  protected internal override Expression Accept(ExpressionVisitor visitor)
122  {
123  return visitor.VisitSwitch(this);
124  }
125 
131  [global::__DynamicallyInvokable]
132  public SwitchExpression Update(Expression switchValue, IEnumerable<SwitchCase> cases, Expression defaultBody)
133  {
134  if (switchValue == SwitchValue && cases == Cases && defaultBody == DefaultBody)
135  {
136  return this;
137  }
138  return Expression.Switch(Type, switchValue, defaultBody, Comparison, cases);
139  }
140  }
141 }
ReadOnlyCollection< SwitchCase > Cases
Gets the collection of T:System.Linq.Expressions.SwitchCase objects for the switch.
SwitchExpression Update(Expression switchValue, IEnumerable< SwitchCase > cases, Expression defaultBody)
Creates a new expression that is like this one, but using the supplied children. If all of the childr...
Provides the base class for a generic read-only collection.
Discovers the attributes of a method and provides access to method metadata.
Definition: MethodInfo.cs:13
Definition: __Canon.cs:3
Expression SwitchValue
Gets the test for the switch.
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
Definition: IEnumerable.cs:9
MethodInfo Comparison
Gets the equality comparison method, if any.
sealed override ExpressionType NodeType
Returns the node type of this Expression. Extension nodes should return F:System.Linq....
Provides the base class from which the classes that represent expression tree nodes are derived....
Definition: Expression.cs:17
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Represents a control expression that handles multiple selections by passing control to T:System....
ExpressionType
Describes the node types for the nodes of an expression tree.
sealed override Type Type
Gets the static type of the expression that this T:System.Linq.Expressions.Expression represents.
Expression DefaultBody
Gets the test for the switch.