Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / Microsoft / Scripting / Actions / DynamicMetaObject.cs / 1305376 / DynamicMetaObject.cs
/* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Collections.Generic; using System.Dynamic.Utils; using System.Linq.Expressions; using System.Reflection; #if SILVERLIGHT using System.Core; #else using System.Runtime.Remoting; #endif namespace System.Dynamic { ////// Represents the dynamic binding and a binding logic of an object participating in the dynamic binding. /// public class DynamicMetaObject { private readonly Expression _expression; private readonly BindingRestrictions _restrictions; private readonly object _value; private readonly bool _hasValue; ////// Represents an empty array of type [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")] public static readonly DynamicMetaObject[] EmptyMetaObjects = new DynamicMetaObject[0]; ///. This field is read only. /// /// Initializes a new instance of the /// The expression representing thisclass. /// during the dynamic binding process. /// The set of binding restrictions under which the binding is valid. public DynamicMetaObject(Expression expression, BindingRestrictions restrictions) { ContractUtils.RequiresNotNull(expression, "expression"); ContractUtils.RequiresNotNull(restrictions, "restrictions"); _expression = expression; _restrictions = restrictions; } /// /// Initializes a new instance of the /// The expression representing thisclass. /// during the dynamic binding process. /// The set of binding restrictions under which the binding is valid. /// The runtime value represented by the . public DynamicMetaObject(Expression expression, BindingRestrictions restrictions, object value) : this(expression, restrictions) { _value = value; _hasValue = true; } /// /// The expression representing the public Expression Expression { get { return _expression; } } ///during the dynamic binding process. /// /// The set of binding restrictions under which the binding is valid. /// public BindingRestrictions Restrictions { get { return _restrictions; } } ////// The runtime value represented by this public object Value { get { return _value; } } ///. /// /// Gets a value indicating whether the public bool HasValue { get { return _hasValue; } } ///has the runtime value. /// /// Gets the public Type RuntimeType { get { if (_hasValue) { Type ct = Expression.Type; // valuetype at compile tyme, type cannot change. if (ct.IsValueType) { return ct; } if (_value != null) { return _value.GetType(); } else { return null; } } else { return null; } } } ///of the runtime value or null if the has no value associated with it. /// /// Gets the limit type of the ///. /// Represents the most specific type known about the object represented by the public Type LimitType { get { return RuntimeType ?? Expression.Type; } } ///. if runtime value is available, a type of the otherwise. /// Performs the binding of the dynamic conversion operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The new public virtual DynamicMetaObject BindConvert(ConvertBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackConvert(this); } ///representing the result of the binding. /// Performs the binding of the dynamic get member operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The new public virtual DynamicMetaObject BindGetMember(GetMemberBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackGetMember(this); } ///representing the result of the binding. /// Performs the binding of the dynamic set member operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The representing the value for the set member operation. /// The new public virtual DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackSetMember(this, value); } ///representing the result of the binding. /// Performs the binding of the dynamic delete member operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The new public virtual DynamicMetaObject BindDeleteMember(DeleteMemberBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackDeleteMember(this); } ///representing the result of the binding. /// Performs the binding of the dynamic get index operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - indexes for the get index operation. /// The new public virtual DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackGetIndex(this, indexes); } ///representing the result of the binding. /// Performs the binding of the dynamic set index operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - indexes for the set index operation. /// The representing the value for the set index operation. /// The new public virtual DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackSetIndex(this, indexes, value); } ///representing the result of the binding. /// Performs the binding of the dynamic delete index operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - indexes for the delete index operation. /// The new public virtual DynamicMetaObject BindDeleteIndex(DeleteIndexBinder binder, DynamicMetaObject[] indexes) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackDeleteIndex(this, indexes); } ///representing the result of the binding. /// Performs the binding of the dynamic invoke member operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - arguments to the invoke member operation. /// The new public virtual DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackInvokeMember(this, args); } ///representing the result of the binding. /// Performs the binding of the dynamic invoke operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - arguments to the invoke operation. /// The new public virtual DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackInvoke(this, args); } ///representing the result of the binding. /// Performs the binding of the dynamic create instance operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - arguments to the create instance operation. /// The new public virtual DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackCreateInstance(this, args); } ///representing the result of the binding. /// Performs the binding of the dynamic unary operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The new public virtual DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackUnaryOperation(this); } ///representing the result of the binding. /// Performs the binding of the dynamic binary operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An instance of the representing the right hand side of the binary operation. /// The new public virtual DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackBinaryOperation(this, arg); } ///representing the result of the binding. /// Returns the enumeration of all dynamic member names. /// ///The list of dynamic member names. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] public virtual IEnumerableGetDynamicMemberNames() { return new string[0]; } /// /// Returns the list of expressions represented by the /// An array ofinstances. /// instances to extract expressions from. /// The array of expressions. internal static Expression[] GetExpressions(DynamicMetaObject[] objects) { ContractUtils.RequiresNotNull(objects, "objects"); Expression[] res = new Expression[objects.Length]; for (int i = 0; i < objects.Length; i++) { DynamicMetaObject mo = objects[i]; ContractUtils.RequiresNotNull(mo, "objects"); Expression expr = mo.Expression; ContractUtils.RequiresNotNull(expr, "objects"); res[i] = expr; } return res; } ////// Creates a meta-object for the specified object. /// /// The object to get a meta-object for. /// The expression representing thisduring the dynamic binding process. /// /// If the given object implements public static DynamicMetaObject Create(object value, Expression expression) { ContractUtils.RequiresNotNull(expression, "expression"); IDynamicMetaObjectProvider ido = value as IDynamicMetaObjectProvider; #if !SILVERLIGHT if (ido != null && !RemotingServices.IsObjectOutOfAppDomain(value)) { #else if (ido != null) { #endif var idoMetaObject = ido.GetMetaObject(expression); if (idoMetaObject == null || !idoMetaObject.HasValue || idoMetaObject.Value == null || (object)idoMetaObject.Expression != (object)expression) { throw Error.InvalidMetaObjectCreated(ido.GetType()); } return idoMetaObject; } else { return new DynamicMetaObject(expression, BindingRestrictions.Empty, value); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Collections.Generic; using System.Dynamic.Utils; using System.Linq.Expressions; using System.Reflection; #if SILVERLIGHT using System.Core; #else using System.Runtime.Remoting; #endif namespace System.Dynamic { ///and is not a remote object from outside the current AppDomain, /// returns the object's specific meta-object returned by . Otherwise a plain new meta-object /// with no restrictions is created and returned. /// /// Represents the dynamic binding and a binding logic of an object participating in the dynamic binding. /// public class DynamicMetaObject { private readonly Expression _expression; private readonly BindingRestrictions _restrictions; private readonly object _value; private readonly bool _hasValue; ////// Represents an empty array of type [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2105:ArrayFieldsShouldNotBeReadOnly")] public static readonly DynamicMetaObject[] EmptyMetaObjects = new DynamicMetaObject[0]; ///. This field is read only. /// /// Initializes a new instance of the /// The expression representing thisclass. /// during the dynamic binding process. /// The set of binding restrictions under which the binding is valid. public DynamicMetaObject(Expression expression, BindingRestrictions restrictions) { ContractUtils.RequiresNotNull(expression, "expression"); ContractUtils.RequiresNotNull(restrictions, "restrictions"); _expression = expression; _restrictions = restrictions; } /// /// Initializes a new instance of the /// The expression representing thisclass. /// during the dynamic binding process. /// The set of binding restrictions under which the binding is valid. /// The runtime value represented by the . public DynamicMetaObject(Expression expression, BindingRestrictions restrictions, object value) : this(expression, restrictions) { _value = value; _hasValue = true; } /// /// The expression representing the public Expression Expression { get { return _expression; } } ///during the dynamic binding process. /// /// The set of binding restrictions under which the binding is valid. /// public BindingRestrictions Restrictions { get { return _restrictions; } } ////// The runtime value represented by this public object Value { get { return _value; } } ///. /// /// Gets a value indicating whether the public bool HasValue { get { return _hasValue; } } ///has the runtime value. /// /// Gets the public Type RuntimeType { get { if (_hasValue) { Type ct = Expression.Type; // valuetype at compile tyme, type cannot change. if (ct.IsValueType) { return ct; } if (_value != null) { return _value.GetType(); } else { return null; } } else { return null; } } } ///of the runtime value or null if the has no value associated with it. /// /// Gets the limit type of the ///. /// Represents the most specific type known about the object represented by the public Type LimitType { get { return RuntimeType ?? Expression.Type; } } ///. if runtime value is available, a type of the otherwise. /// Performs the binding of the dynamic conversion operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The new public virtual DynamicMetaObject BindConvert(ConvertBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackConvert(this); } ///representing the result of the binding. /// Performs the binding of the dynamic get member operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The new public virtual DynamicMetaObject BindGetMember(GetMemberBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackGetMember(this); } ///representing the result of the binding. /// Performs the binding of the dynamic set member operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The representing the value for the set member operation. /// The new public virtual DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackSetMember(this, value); } ///representing the result of the binding. /// Performs the binding of the dynamic delete member operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The new public virtual DynamicMetaObject BindDeleteMember(DeleteMemberBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackDeleteMember(this); } ///representing the result of the binding. /// Performs the binding of the dynamic get index operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - indexes for the get index operation. /// The new public virtual DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackGetIndex(this, indexes); } ///representing the result of the binding. /// Performs the binding of the dynamic set index operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - indexes for the set index operation. /// The representing the value for the set index operation. /// The new public virtual DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackSetIndex(this, indexes, value); } ///representing the result of the binding. /// Performs the binding of the dynamic delete index operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - indexes for the delete index operation. /// The new public virtual DynamicMetaObject BindDeleteIndex(DeleteIndexBinder binder, DynamicMetaObject[] indexes) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackDeleteIndex(this, indexes); } ///representing the result of the binding. /// Performs the binding of the dynamic invoke member operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - arguments to the invoke member operation. /// The new public virtual DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackInvokeMember(this, args); } ///representing the result of the binding. /// Performs the binding of the dynamic invoke operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - arguments to the invoke operation. /// The new public virtual DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackInvoke(this, args); } ///representing the result of the binding. /// Performs the binding of the dynamic create instance operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An array of instances - arguments to the create instance operation. /// The new public virtual DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackCreateInstance(this, args); } ///representing the result of the binding. /// Performs the binding of the dynamic unary operation. /// /// An instance of thethat represents the details of the dynamic operation. /// The new public virtual DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackUnaryOperation(this); } ///representing the result of the binding. /// Performs the binding of the dynamic binary operation. /// /// An instance of thethat represents the details of the dynamic operation. /// An instance of the representing the right hand side of the binary operation. /// The new public virtual DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackBinaryOperation(this, arg); } ///representing the result of the binding. /// Returns the enumeration of all dynamic member names. /// ///The list of dynamic member names. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] public virtual IEnumerableGetDynamicMemberNames() { return new string[0]; } /// /// Returns the list of expressions represented by the /// An array ofinstances. /// instances to extract expressions from. /// The array of expressions. internal static Expression[] GetExpressions(DynamicMetaObject[] objects) { ContractUtils.RequiresNotNull(objects, "objects"); Expression[] res = new Expression[objects.Length]; for (int i = 0; i < objects.Length; i++) { DynamicMetaObject mo = objects[i]; ContractUtils.RequiresNotNull(mo, "objects"); Expression expr = mo.Expression; ContractUtils.RequiresNotNull(expr, "objects"); res[i] = expr; } return res; } ////// Creates a meta-object for the specified object. /// /// The object to get a meta-object for. /// The expression representing thisduring the dynamic binding process. /// /// If the given object implements public static DynamicMetaObject Create(object value, Expression expression) { ContractUtils.RequiresNotNull(expression, "expression"); IDynamicMetaObjectProvider ido = value as IDynamicMetaObjectProvider; #if !SILVERLIGHT if (ido != null && !RemotingServices.IsObjectOutOfAppDomain(value)) { #else if (ido != null) { #endif var idoMetaObject = ido.GetMetaObject(expression); if (idoMetaObject == null || !idoMetaObject.HasValue || idoMetaObject.Value == null || (object)idoMetaObject.Expression != (object)expression) { throw Error.InvalidMetaObjectCreated(ido.GetType()); } return idoMetaObject; } else { return new DynamicMetaObject(expression, BindingRestrictions.Empty, value); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.and is not a remote object from outside the current AppDomain, /// returns the object's specific meta-object returned by . Otherwise a plain new meta-object /// with no restrictions is created and returned. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypeSystemProvider.cs
- PingReply.cs
- ControlValuePropertyAttribute.cs
- ProcessHostConfigUtils.cs
- CommandField.cs
- Utility.cs
- PersonalizationEntry.cs
- RtfFormatStack.cs
- ModuleBuilder.cs
- RenderTargetBitmap.cs
- _AuthenticationState.cs
- SwitchAttribute.cs
- DataRelationPropertyDescriptor.cs
- NullableDecimalSumAggregationOperator.cs
- XhtmlConformanceSection.cs
- XmlIgnoreAttribute.cs
- DSASignatureFormatter.cs
- ContextMenuStripGroupCollection.cs
- RandomNumberGenerator.cs
- CodePageEncoding.cs
- OneToOneMappingSerializer.cs
- CurrentChangingEventArgs.cs
- DeviceFilterEditorDialog.cs
- DataGridBeginningEditEventArgs.cs
- BuildDependencySet.cs
- AsyncResult.cs
- VisualStyleInformation.cs
- SchemaImporterExtensionsSection.cs
- SerializableAttribute.cs
- COSERVERINFO.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- FormsAuthenticationEventArgs.cs
- Point.cs
- EntityDataSourceValidationException.cs
- Message.cs
- XmlCustomFormatter.cs
- Wildcard.cs
- ConfigXmlCDataSection.cs
- ObjectHandle.cs
- TypedColumnHandler.cs
- SchemaEntity.cs
- WebPartConnectionsConfigureVerb.cs
- BrowserTree.cs
- CodeDirectionExpression.cs
- SoapSchemaExporter.cs
- TrackingProfile.cs
- ThreadStaticAttribute.cs
- HyperLink.cs
- RSAPKCS1SignatureDeformatter.cs
- RemoveStoryboard.cs
- ByteConverter.cs
- HTMLTextWriter.cs
- DataSourceCollectionBase.cs
- DbRetry.cs
- ListBindingConverter.cs
- DataControlButton.cs
- NumberFormatter.cs
- BindingsCollection.cs
- TypedElement.cs
- Preprocessor.cs
- EntityParameterCollection.cs
- AffineTransform3D.cs
- TransformerConfigurationWizardBase.cs
- ProtocolsSection.cs
- Rotation3DAnimation.cs
- PropertySegmentSerializationProvider.cs
- BuildResult.cs
- UnsafeNativeMethods.cs
- AttributeCollection.cs
- ReadOnlyTernaryTree.cs
- MemoryStream.cs
- WebContext.cs
- RijndaelManaged.cs
- ProgressiveCrcCalculatingStream.cs
- SmiSettersStream.cs
- Serializer.cs
- ControlBindingsConverter.cs
- ConsumerConnectionPointCollection.cs
- DoubleUtil.cs
- ExecutionTracker.cs
- GridViewSortEventArgs.cs
- XPathSelectionIterator.cs
- PropertyCollection.cs
- CorrelationHandle.cs
- CodeMemberProperty.cs
- StructuredType.cs
- PreloadHost.cs
- LockedActivityGlyph.cs
- WorkflowInstanceExtensionProvider.cs
- DynamicDiscoSearcher.cs
- WindowHideOrCloseTracker.cs
- ScriptResourceInfo.cs
- SudsCommon.cs
- TabOrder.cs
- LoadMessageLogger.cs
- PositiveTimeSpanValidator.cs
- X509ChainPolicy.cs
- WebPartConnectionsDisconnectVerb.cs
- UnitControl.cs
- Guid.cs