mscorlib(4.0.0.0) API with additions
DynamicMetaObject.cs
2 using System.Dynamic.Utils;
5 
6 namespace System.Dynamic
7 {
9  [global::__DynamicallyInvokable]
10  public class DynamicMetaObject
11  {
12  private readonly Expression _expression;
13 
14  private readonly BindingRestrictions _restrictions;
15 
16  private readonly object _value;
17 
18  private readonly bool _hasValue;
19 
21  [global::__DynamicallyInvokable]
22  public static readonly DynamicMetaObject[] EmptyMetaObjects = new DynamicMetaObject[0];
23 
26  [global::__DynamicallyInvokable]
27  public Expression Expression
28  {
29  [global::__DynamicallyInvokable]
30  get
31  {
32  return _expression;
33  }
34  }
35 
38  [global::__DynamicallyInvokable]
40  {
41  [global::__DynamicallyInvokable]
42  get
43  {
44  return _restrictions;
45  }
46  }
47 
50  [global::__DynamicallyInvokable]
51  public object Value
52  {
53  [global::__DynamicallyInvokable]
54  get
55  {
56  return _value;
57  }
58  }
59 
62  [global::__DynamicallyInvokable]
63  public bool HasValue
64  {
65  [global::__DynamicallyInvokable]
66  get
67  {
68  return _hasValue;
69  }
70  }
71 
74  [global::__DynamicallyInvokable]
75  public Type RuntimeType
76  {
77  [global::__DynamicallyInvokable]
78  get
79  {
80  if (_hasValue)
81  {
82  Type type = Expression.Type;
83  if (type.IsValueType)
84  {
85  return type;
86  }
87  if (_value != null)
88  {
89  return _value.GetType();
90  }
91  return null;
92  }
93  return null;
94  }
95  }
96 
100  [global::__DynamicallyInvokable]
101  public Type LimitType
102  {
103  [global::__DynamicallyInvokable]
104  get
105  {
106  return RuntimeType ?? Expression.Type;
107  }
108  }
109 
113  [global::__DynamicallyInvokable]
114  public DynamicMetaObject(Expression expression, BindingRestrictions restrictions)
115  {
116  ContractUtils.RequiresNotNull(expression, "expression");
117  ContractUtils.RequiresNotNull(restrictions, "restrictions");
118  _expression = expression;
119  _restrictions = restrictions;
120  }
121 
126  [global::__DynamicallyInvokable]
127  public DynamicMetaObject(Expression expression, BindingRestrictions restrictions, object value)
128  : this(expression, restrictions)
129  {
130  _value = value;
131  _hasValue = true;
132  }
133 
137  [global::__DynamicallyInvokable]
139  {
140  ContractUtils.RequiresNotNull(binder, "binder");
141  return binder.FallbackConvert(this);
142  }
143 
147  [global::__DynamicallyInvokable]
149  {
150  ContractUtils.RequiresNotNull(binder, "binder");
151  return binder.FallbackGetMember(this);
152  }
153 
158  [global::__DynamicallyInvokable]
160  {
161  ContractUtils.RequiresNotNull(binder, "binder");
162  return binder.FallbackSetMember(this, value);
163  }
164 
168  [global::__DynamicallyInvokable]
170  {
171  ContractUtils.RequiresNotNull(binder, "binder");
172  return binder.FallbackDeleteMember(this);
173  }
174 
179  [global::__DynamicallyInvokable]
181  {
182  ContractUtils.RequiresNotNull(binder, "binder");
183  return binder.FallbackGetIndex(this, indexes);
184  }
185 
191  [global::__DynamicallyInvokable]
193  {
194  ContractUtils.RequiresNotNull(binder, "binder");
195  return binder.FallbackSetIndex(this, indexes, value);
196  }
197 
202  [global::__DynamicallyInvokable]
204  {
205  ContractUtils.RequiresNotNull(binder, "binder");
206  return binder.FallbackDeleteIndex(this, indexes);
207  }
208 
213  [global::__DynamicallyInvokable]
215  {
216  ContractUtils.RequiresNotNull(binder, "binder");
217  return binder.FallbackInvokeMember(this, args);
218  }
219 
224  [global::__DynamicallyInvokable]
226  {
227  ContractUtils.RequiresNotNull(binder, "binder");
228  return binder.FallbackInvoke(this, args);
229  }
230 
235  [global::__DynamicallyInvokable]
237  {
238  ContractUtils.RequiresNotNull(binder, "binder");
239  return binder.FallbackCreateInstance(this, args);
240  }
241 
245  [global::__DynamicallyInvokable]
247  {
248  ContractUtils.RequiresNotNull(binder, "binder");
249  return binder.FallbackUnaryOperation(this);
250  }
251 
256  [global::__DynamicallyInvokable]
258  {
259  ContractUtils.RequiresNotNull(binder, "binder");
260  return binder.FallbackBinaryOperation(this, arg);
261  }
262 
265  [global::__DynamicallyInvokable]
267  {
268  return new string[0];
269  }
270 
271  internal static Expression[] GetExpressions(DynamicMetaObject[] objects)
272  {
273  ContractUtils.RequiresNotNull(objects, "objects");
274  Expression[] array = new Expression[objects.Length];
275  for (int i = 0; i < objects.Length; i++)
276  {
277  DynamicMetaObject dynamicMetaObject = objects[i];
278  ContractUtils.RequiresNotNull(dynamicMetaObject, "objects");
279  Expression expression = dynamicMetaObject.Expression;
280  ContractUtils.RequiresNotNull(expression, "objects");
281  array[i] = expression;
282  }
283  return array;
284  }
285 
290  [global::__DynamicallyInvokable]
291  public static DynamicMetaObject Create(object value, Expression expression)
292  {
293  ContractUtils.RequiresNotNull(expression, "expression");
294  IDynamicMetaObjectProvider dynamicMetaObjectProvider = value as IDynamicMetaObjectProvider;
295  if (dynamicMetaObjectProvider != null && !RemotingServices.IsObjectOutOfAppDomain(value))
296  {
297  DynamicMetaObject metaObject = dynamicMetaObjectProvider.GetMetaObject(expression);
298  if (metaObject == null || !metaObject.HasValue || metaObject.Value == null || metaObject.Expression != expression)
299  {
300  throw Error.InvalidMetaObjectCreated(dynamicMetaObjectProvider.GetType());
301  }
302  return metaObject;
303  }
304  return new DynamicMetaObject(expression, BindingRestrictions.Empty, value);
305  }
306  }
307 }
Represents the dynamic create operation at the call site, providing the binding semantic and the deta...
Represents the dynamic set index operation at the call site, providing the binding semantic and the d...
Represents a dynamic object, that can have its operations bound at runtime.
DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value)
Performs the binding of the dynamic set member operation if the target dynamic object cannot bind.
virtual DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
Performs the binding of the dynamic invoke operation.
virtual DynamicMetaObject BindDeleteMember(DeleteMemberBinder binder)
Performs the binding of the dynamic delete member operation.
Represents the convert dynamic operation at the call site, providing the binding semantic and the det...
Definition: ConvertBinder.cs:7
virtual DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
Performs the binding of the dynamic invoke member operation.
Represents the dynamic get member operation at the call site, providing the binding semantic and the ...
Represents the dynamic binding and a binding logic of an object participating in the dynamic binding.
Represents the dynamic set member operation at the call site, providing the binding semantic and the ...
DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args)
Performs the binding of the dynamic invoke operation if the target dynamic object cannot bind.
Definition: InvokeBinder.cs:51
Definition: __Canon.cs:3
DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg)
Performs the binding of the binary dynamic operation if the target dynamic object cannot bind.
object Value
The runtime value represented by this T:System.Dynamic.DynamicMetaObject.
DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args)
Performs the binding of the dynamic invoke member operation if the target dynamic object cannot bind.
virtual DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
Performs the binding of the dynamic create instance operation.
Represents the invoke dynamic operation at the call site, providing the binding semantic and the deta...
Definition: InvokeBinder.cs:7
static readonly BindingRestrictions Empty
Represents an empty set of binding restrictions. This field is read only.
DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target)
Performs the binding of the unary dynamic operation if the target dynamic object cannot bind.
Expression Expression
The expression representing the T:System.Dynamic.DynamicMetaObject during the dynamic binding process...
DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value)
Performs the binding of the dynamic set index operation if the target dynamic object cannot bind.
DynamicMetaObject FallbackGetMember(DynamicMetaObject target)
Performs the binding of the dynamic get member operation if the target dynamic object cannot bind.
DynamicMetaObject FallbackDeleteMember(DynamicMetaObject target)
Performs the binding of the dynamic delete member operation if the target dynamic object cannot bind.
virtual DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
Performs the binding of the dynamic binary operation.
DynamicMetaObject FallbackConvert(DynamicMetaObject target)
Performs the binding of the dynamic convert operation if the target dynamic object cannot bind.
Provides the base class from which the classes that represent expression tree nodes are derived....
Definition: Expression.cs:17
virtual DynamicMetaObject BindConvert(ConvertBinder binder)
Performs the binding of the dynamic conversion operation.
virtual IEnumerable< string > GetDynamicMemberNames()
Returns the enumeration of all dynamic member names.
virtual DynamicMetaObject BindGetMember(GetMemberBinder binder)
Performs the binding of the dynamic get member operation.
static bool IsObjectOutOfAppDomain(object tp)
Returns a Boolean value that indicates whether the object specified by the given transparent proxy is...
BindingRestrictions Restrictions
The set of binding restrictions under which the binding is valid.
Represents the invoke member dynamic operation at the call site, providing the binding semantic and t...
virtual DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
Performs the binding of the dynamic get index operation.
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
DynamicMetaObject(Expression expression, BindingRestrictions restrictions)
Initializes a new instance of the T:System.Dynamic.DynamicMetaObject class.
DynamicMetaObject FallbackCreateInstance(DynamicMetaObject target, DynamicMetaObject[] args)
Performs the binding of the dynamic create operation if the target dynamic object cannot bind.
DynamicMetaObject FallbackDeleteIndex(DynamicMetaObject target, DynamicMetaObject[] indexes)
Performs the binding of the dynamic delete index operation if the target dynamic object cannot bind.
bool IsValueType
Gets a value indicating whether the T:System.Type is a value type.
Definition: Type.cs:445
virtual DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value)
Performs the binding of the dynamic set member operation.
Type RuntimeType
Gets the T:System.Type of the runtime value or null if the T:System.Dynamic.DynamicMetaObject has no ...
bool HasValue
Gets a value indicating whether the T:System.Dynamic.DynamicMetaObject has the runtime value.
Represents a set of binding restrictions on the T:System.Dynamic.DynamicMetaObject under which the dy...
DynamicMetaObject FallbackGetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes)
Performs the binding of the dynamic get index operation if the target dynamic object cannot bind.
DynamicMetaObject GetMetaObject(Expression parameter)
Returns the T:System.Dynamic.DynamicMetaObject responsible for binding operations performed on this o...
Represents the dynamic get index operation at the call site, providing the binding semantic and the d...
DynamicMetaObject(Expression expression, BindingRestrictions restrictions, object value)
Initializes a new instance of the T:System.Dynamic.DynamicMetaObject class.
Represents the dynamic delete index operation at the call site, providing the binding semantic and th...
virtual DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
Performs the binding of the dynamic set index operation.
Represents the binary dynamic operation at the call site, providing the binding semantic and the deta...
static readonly DynamicMetaObject [] EmptyMetaObjects
Represents an empty array of type T:System.Dynamic.DynamicMetaObject. This field is read only.
Represents the unary dynamic operation at the call site, providing the binding semantic and the detai...
static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Gets the T:System.Type with the specified name, specifying whether to throw an exception if the type ...
Definition: Type.cs:853
virtual DynamicMetaObject BindDeleteIndex(DeleteIndexBinder binder, DynamicMetaObject[] indexes)
Performs the binding of the dynamic delete index operation.
static DynamicMetaObject Create(object value, Expression expression)
Creates a meta-object for the specified object.
virtual DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
Performs the binding of the dynamic unary operation.
Provides several methods for using and publishing remoted objects and proxies. This class cannot be i...
Type?? LimitType
Gets the limit type of the T:System.Dynamic.DynamicMetaObject.
Represents the dynamic delete member operation at the call site, providing the binding semantic and t...