10 [DebuggerTypeProxy(typeof(BindingRestrictionsProxy))]
11 [DebuggerDisplay(
"{DebugView}")]
12 [global::__DynamicallyInvokable]
15 private sealed
class TestBuilder
17 private struct AndNode
24 private readonly Set<BindingRestrictions> _unique =
new Set<BindingRestrictions>();
30 if (!_unique.Contains(restrictions))
32 _unique.Add(restrictions);
33 Push(restrictions.GetExpression(), 0);
40 while (_tests.Count > 0)
42 expression =
Expression.AndAlso(_tests.Pop().Node, expression);
49 while (_tests.Count > 0 && _tests.Peek().Depth == depth)
51 node =
Expression.AndAlso(_tests.Pop().Node, node);
54 _tests.Push(
new AndNode
76 throw ContractUtils.Unreachable;
84 internal CustomRestriction(
Expression expression)
86 _expression = expression;
89 public override bool Equals(
object obj)
91 CustomRestriction customRestriction = obj as CustomRestriction;
92 if (customRestriction !=
null)
94 return customRestriction._expression == _expression;
99 public override int GetHashCode()
101 return 0x40000000 ^ _expression.GetHashCode();
114 private readonly
Type _type;
118 _expression = parameter;
122 public override bool Equals(
object obj)
124 TypeRestriction typeRestriction = obj as TypeRestriction;
125 if (typeRestriction !=
null && TypeUtils.AreEquivalent(typeRestriction._type, _type))
127 return typeRestriction._expression == _expression;
132 public override int GetHashCode()
134 return 0x10000000 ^ _expression.GetHashCode() ^ _type.GetHashCode();
139 return Expression.TypeEqual(_expression, _type);
147 private readonly
object _instance;
149 internal InstanceRestriction(
Expression parameter,
object instance)
151 _expression = parameter;
152 _instance = instance;
155 public override bool Equals(
object obj)
157 InstanceRestriction instanceRestriction = obj as InstanceRestriction;
158 if (instanceRestriction !=
null && instanceRestriction._instance == _instance)
160 return instanceRestriction._expression == _expression;
165 public override int GetHashCode()
172 if (_instance ==
null)
184 private sealed
class BindingRestrictionsProxy
188 public bool IsEmpty => _node ==
Empty;
190 public Expression Test => _node.ToExpression();
202 MergedRestriction mergedRestriction = bindingRestrictions as MergedRestriction;
203 if (mergedRestriction !=
null)
205 stack.Push(mergedRestriction.Right);
206 stack.Push(mergedRestriction.Left);
210 list.Add(bindingRestrictions);
213 while (stack.Count > 0);
214 return list.ToArray();
223 public override string ToString()
225 return _node.DebugView;
230 [global::__DynamicallyInvokable]
233 private const int TypeRestrictionHash = 268435456;
235 private const int InstanceRestrictionHash = 536870912;
237 private const int CustomRestrictionHash = 1073741824;
250 [global::__DynamicallyInvokable]
253 ContractUtils.RequiresNotNull(restrictions,
"restrictions");
258 if (restrictions ==
Empty)
262 return new MergedRestriction(
this, restrictions);
269 [global::__DynamicallyInvokable]
272 ContractUtils.RequiresNotNull(expression,
"expression");
273 ContractUtils.RequiresNotNull(type,
"type");
274 return new TypeRestriction(expression, type);
279 if (obj.Value ==
null && obj.HasValue)
290 [global::__DynamicallyInvokable]
293 ContractUtils.RequiresNotNull(expression,
"expression");
294 return new InstanceRestriction(expression, instance);
300 [global::__DynamicallyInvokable]
303 ContractUtils.RequiresNotNull(expression,
"expression");
304 ContractUtils.Requires(expression.Type == typeof(
bool),
"expression");
305 return new CustomRestriction(expression);
311 [global::__DynamicallyInvokable]
315 if (contributingObjects !=
null)
319 if (contributingObject !=
null)
321 bindingRestrictions = bindingRestrictions.
Merge(contributingObject.
Restrictions);
324 return bindingRestrictions;
326 return bindingRestrictions;
331 [global::__DynamicallyInvokable]
338 TestBuilder testBuilder =
new TestBuilder();
344 MergedRestriction mergedRestriction = bindingRestrictions as MergedRestriction;
345 if (mergedRestriction !=
null)
347 stack.Push(mergedRestriction.Right);
348 stack.Push(mergedRestriction.Left);
352 testBuilder.Append(bindingRestrictions);
355 while (stack.Count > 0);
356 return testBuilder.ToExpression();
static int GetHashCode(object o)
Serves as a hash function for a particular object, and is suitable for use in algorithms and data str...
static BindingRestrictions GetExpressionRestriction(Expression expression)
Creates the binding restriction that checks the expression for arbitrary immutable properties.
static BindingRestrictions GetTypeRestriction(Expression expression, Type type)
Creates the binding restriction that check the expression for runtime type identity.
static readonly BindingRestrictions Empty
Represents an empty set of binding restrictions. This field is read only.
BindingRestrictions Merge(BindingRestrictions restrictions)
Merges the set of binding restrictions with the current binding restrictions.
Represents a weak reference, which references an object while still allowing that object to be reclai...
Provides the base class from which the classes that represent expression tree nodes are derived....
Represents type declarations: class types, interface types, array types, value types,...
static BindingRestrictions GetInstanceRestriction(Expression expression, object instance)
Creates the binding restriction that checks the expression for object instance identity.
Represents a named parameter expression.
Represents a set of binding restrictions on the T:System.Dynamic.DynamicMetaObject under which the dy...
Represents a collection of objects that can be individually accessed by index.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
static BindingRestrictions Combine(IList< DynamicMetaObject > contributingObjects)
Combines binding restrictions from the list of T:System.Dynamic.DynamicMetaObject instances into one ...
Expression ToExpression()
Creates the T:System.Linq.Expressions.Expression representing the binding restrictions.
Provides a set of static methods and properties that provide support for compilers....