Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BindingRestrictions.cs
Go to the documentation of this file.
7
8namespace System.Dynamic;
9
10[DebuggerTypeProxy(typeof(BindingRestrictionsProxy))]
11[DebuggerDisplay("{DebugView}")]
12public abstract class BindingRestrictions
13{
14 private sealed class TestBuilder
15 {
16 private struct AndNode
17 {
18 internal int Depth;
19
20 internal Expression Node;
21 }
22
24
25 private readonly Stack<AndNode> _tests = new Stack<AndNode>();
26
28 {
30 {
31 Push(restrictions.GetExpression(), 0);
32 }
33 }
34
36 {
37 Expression expression = _tests.Pop().Node;
38 while (_tests.Count > 0)
39 {
41 }
42 return expression;
43 }
44
45 private void Push(Expression node, int depth)
46 {
47 while (_tests.Count > 0 && _tests.Peek().Depth == depth)
48 {
49 node = Expression.AndAlso(_tests.Pop().Node, node);
50 depth++;
51 }
52 _tests.Push(new AndNode
53 {
54 Node = node,
55 Depth = depth
56 });
57 }
58 }
59
61 {
62 internal readonly BindingRestrictions Left;
63
64 internal readonly BindingRestrictions Right;
65
67 {
68 Left = left;
69 Right = right;
70 }
71
72 internal override Expression GetExpression()
73 {
77 while (true)
78 {
80 {
81 stack.Push(mergedRestriction.Right);
83 continue;
84 }
86 if (stack.Count == 0)
87 {
88 break;
89 }
90 bindingRestrictions = stack.Pop();
91 }
92 return testBuilder.ToExpression();
93 }
94 }
95
97 {
98 private readonly Expression _expression;
99
104
105 public override bool Equals([NotNullWhen(true)] object obj)
106 {
108 {
109 return customRestriction._expression == _expression;
110 }
111 return false;
112 }
113
114 public override int GetHashCode()
115 {
116 return 0x24924924 ^ _expression.GetHashCode();
117 }
118
119 internal override Expression GetExpression()
120 {
121 return _expression;
122 }
123 }
124
126 {
127 private readonly Expression _expression;
128
129 private readonly Type _type;
130
136
137 public override bool Equals([NotNullWhen(true)] object obj)
138 {
140 {
142 }
143 return false;
144 }
145
146 public override int GetHashCode()
147 {
148 return 0x49249249 ^ _expression.GetHashCode() ^ _type.GetHashCode();
149 }
150
151 internal override Expression GetExpression()
152 {
154 }
155 }
156
158 {
159 private readonly Expression _expression;
160
161 private readonly object _instance;
162
163 internal InstanceRestriction(Expression parameter, object instance)
164 {
166 _instance = instance;
167 }
168
169 public override bool Equals([NotNullWhen(true)] object obj)
170 {
172 {
173 return instanceRestriction._instance == _instance;
174 }
175 return false;
176 }
177
178 public override int GetHashCode()
179 {
180 return -1840700270 ^ RuntimeHelpers.GetHashCode(_instance) ^ _expression.GetHashCode();
181 }
182
192 }
193
194 private sealed class BindingRestrictionsProxy
195 {
196 private readonly BindingRestrictions _node;
197
198 public bool IsEmpty => _node == Empty;
199
201
203 {
204 get
205 {
209 while (true)
210 {
212 {
213 stack.Push(mergedRestriction.Right);
215 continue;
216 }
218 if (stack.Count == 0)
219 {
220 break;
221 }
222 bindingRestrictions = stack.Pop();
223 }
224 return list.ToArray();
225 }
226 }
227
233
234 public override string ToString()
235 {
236 return _node.DebugView;
237 }
238 }
239
241
242 private string DebugView => ToExpression().ToString();
243
245 {
246 }
247
248 internal abstract Expression GetExpression();
249
251 {
253 if (this == Empty)
254 {
255 return restrictions;
256 }
257 if (restrictions == Empty)
258 {
259 return this;
260 }
261 return new MergedRestriction(this, restrictions);
262 }
263
270
272 {
273 if (obj.Value == null && obj.HasValue)
274 {
275 return GetInstanceRestriction(obj.Expression, null);
276 }
277 return GetTypeRestriction(obj.Expression, obj.LimitType);
278 }
279
281 {
283 return new InstanceRestriction(expression, instance);
284 }
285
292
308
310 {
311 return GetExpression();
312 }
313}
void Add(TKey key, TValue value)
override bool Equals([NotNullWhen(true)] object obj)
override bool Equals([NotNullWhen(true)] object obj)
InstanceRestriction(Expression parameter, object instance)
MergedRestriction(BindingRestrictions left, BindingRestrictions right)
readonly HashSet< BindingRestrictions > _unique
void Append(BindingRestrictions restrictions)
override bool Equals([NotNullWhen(true)] object obj)
static BindingRestrictions GetTypeRestriction(DynamicMetaObject obj)
static BindingRestrictions Combine(IList< DynamicMetaObject >? contributingObjects)
BindingRestrictions Merge(BindingRestrictions restrictions)
static readonly BindingRestrictions Empty
static BindingRestrictions GetTypeRestriction(Expression expression, Type type)
static BindingRestrictions GetExpressionRestriction(Expression expression)
static BindingRestrictions GetInstanceRestriction(Expression expression, object? instance)
static void Requires([DoesNotReturnIf(false)] bool precondition, string paramName)
static void RequiresNotNull(object value, string paramName)
static bool AreEquivalent(Type t1, Type t2)
Definition TypeUtils.cs:664
static ConstantExpression Constant(object? value)
static BlockExpression Block(Expression arg0, Expression arg1)
static BinaryExpression NotEqual(Expression left, Expression right)
static BinaryExpression Assign(Expression left, Expression right)
static TypeBinaryExpression TypeEqual(Expression expression, Type type)
static ParameterExpression Parameter(Type type)
static UnaryExpression Convert(Expression expression, Type type)
static BinaryExpression AndAlso(Expression left, Expression right)
static BinaryExpression Equal(Expression left, Expression right)
static readonly ConstantExpression Null
Definition Utils.cs:62
static ConstantExpression Constant(bool value)
Definition Utils.cs:64
override int GetHashCode()
Definition Type.cs:1122