Code:
                         / Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataWebControls / System / Data / WebControls / EntityDataSourceMemberPath.cs / 1 / EntityDataSourceMemberPath.cs
                        
                        
                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
//  
// 
// @owner       [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.EntityClient; 
using System.Data.Metadata.Edm;
using System.Diagnostics; 
using System.Globalization; 
using System.Reflection;
using System.Data.Common; 
using System.Data.Objects;
namespace System.Web.UI.WebControls
{ 
    /// 
    /// A glorified linked list. Describes a chain of properties from a primitive 
    /// type to a root entity. 
    ///  
    class EntityDataSourceMemberPath 
    {
        private readonly EdmProperty property;
        private readonly PropertyInfo propertyInfo;
        private readonly EntityDataSourceMemberPath parent; 
        private readonly bool isLocallyInteresting;
        private readonly Type clrType; 
        private readonly bool isKey; 
        internal EntityDataSourceMemberPath(MetadataWorkspace ocWorkspace, EntityDataSourceMemberPath parent, EdmProperty property, bool isLocallyInteresting) 
        {
            EntityDataSourceUtil.CheckArgumentNull(ocWorkspace, "ocWorkspace");
            EntityDataSourceUtil.CheckArgumentNull(property, "property");
 
            this.property = property;
            this.parent = parent; 
            this.isLocallyInteresting = isLocallyInteresting; 
            this.clrType = EntityDataSourceUtil.GetMemberClrType(ocWorkspace, property);
            this.isKey = IsPropertyAKey(property); 
            // retrieve PropertyInfo (with respect to parent CLR type)
            StructuralType parentType = property.DeclaringType;
            Type parentClrType = EntityDataSourceUtil.GetClrType(ocWorkspace, parentType); 
            this.propertyInfo = EntityDataSourceUtil.GetPropertyInfo(parentClrType, this.property.Name); 
        } 
         ///  
        /// Describes the member path in the form 'property1.property2...'. Use to
        /// determine display name for nested properties in the EDSC.
        ///  
        /// Description of the   
        internal string GetDescription()
        { 
            string prefix = null == this.parent ? string.Empty : this.parent.GetDescription() + "."; 
            return prefix + this.property.Name;
        } 
        /// 
        /// Indicates whether original values of this member should be preserved.
        ///   
        internal bool IsInteresting
        { 
            get 
            {
                // a member path is interesting if anything along the path is interesting 
                return this.isLocallyInteresting || (null != this.parent && this.parent.IsInteresting);
            }
        }
 
        /// 
        /// Indicates whether this member represents a primary key value. 
        ///   
        internal bool IsKey
        { 
            get { return this.isKey; }
        }
        ///  
        /// Indicates whether this member can be assigned a value of null.
        ///   
        internal bool IsNullable 
        {
            get { return this.property.Nullable; } 
        }
        internal bool IsPrimitive
        { 
            get { return this.property.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType; }
        } 
 
        /// 
        /// Gets the CLR type of the last member in the path. 
        ///  
        internal Type ClrType
        {
            get { return this.clrType; } 
        }
 
        internal object GetValue(object entity) 
        {
            object parentObjectValue = GetParentObjectValue(entity, false /* initialize */); 
            if (null == parentObjectValue)
            {
                // use convention that property of null is null
                return null; 
            }
            else 
            { 
                // get this property
                object propertyValue = this.propertyInfo.GetValue(parentObjectValue, new object[] { }); 
                return propertyValue;
            }
        } 
        internal void SetValue(object entity, object value) 
        { 
            object parentObjectValue = GetParentObjectValue(entity, true /* initialize */);
 
            // set property value on parent
            this.propertyInfo.SetValue(parentObjectValue, value, new object[] { });
        }
 
        private object Initialize(object entity)
        { 
            // get parent's value 
            object parentObjectValue = GetParentObjectValue(entity, true /* initialize */);
 
            // construct type instance for this property
            object propertyValue = EntityDataSourceUtil.InitializeType(this.ClrType);
            // set property 
            this.propertyInfo.SetValue(parentObjectValue, propertyValue, new object[] { });
 
            return propertyValue; 
        }
 
        private object GetParentObjectValue(object entity, bool initialize)
        {
            // get parent's value
            object parentObjectValue; 
            if (null == this.parent) 
            { 
                // at the top level, the entity is the value
                parentObjectValue = entity; 
            }
            else
            {
                parentObjectValue = this.parent.GetValue(entity); 
                if (null == parentObjectValue && initialize) 
                { 
                    parentObjectValue = this.parent.Initialize(entity);
                } 
            }
            return parentObjectValue;
        } 
        internal string GetEntitySqlValue() 
        { 
            // it.[member1].[member2]...
            string prefix; 
            if (null != parent)
            {
                prefix = parent.GetEntitySqlValue(); 
            }
            else 
            { 
                prefix = EntityDataSourceUtil.EntitySqlElementAlias;
            } 
            string eSql = prefix + "." + EntityDataSourceUtil.QuoteEntitySqlIdentifier(this.property.Name);
            return eSql; 
        }
 
        private bool IsPropertyAKey(EdmProperty property) 
        {
            bool isKey = false; 
            EntityType entityType = property.DeclaringType as EntityType;
            if (null != entityType)
            {
                isKey = entityType.KeyMembers.Contains(property); 
            }
            return isKey; 
        } 
        public override string ToString() 
        {
            string prefix = null == this.parent ? string.Empty : this.parent.ToString() + "->";
            return prefix + this.property.Name;
        } 
    }
} 
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
//  
// 
// @owner       [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 
using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.EntityClient; 
using System.Data.Metadata.Edm;
using System.Diagnostics; 
using System.Globalization; 
using System.Reflection;
using System.Data.Common; 
using System.Data.Objects;
namespace System.Web.UI.WebControls
{ 
    /// 
    /// A glorified linked list. Describes a chain of properties from a primitive 
    /// type to a root entity. 
    ///  
    class EntityDataSourceMemberPath 
    {
        private readonly EdmProperty property;
        private readonly PropertyInfo propertyInfo;
        private readonly EntityDataSourceMemberPath parent; 
        private readonly bool isLocallyInteresting;
        private readonly Type clrType; 
        private readonly bool isKey; 
        internal EntityDataSourceMemberPath(MetadataWorkspace ocWorkspace, EntityDataSourceMemberPath parent, EdmProperty property, bool isLocallyInteresting) 
        {
            EntityDataSourceUtil.CheckArgumentNull(ocWorkspace, "ocWorkspace");
            EntityDataSourceUtil.CheckArgumentNull(property, "property");
 
            this.property = property;
            this.parent = parent; 
            this.isLocallyInteresting = isLocallyInteresting; 
            this.clrType = EntityDataSourceUtil.GetMemberClrType(ocWorkspace, property);
            this.isKey = IsPropertyAKey(property); 
            // retrieve PropertyInfo (with respect to parent CLR type)
            StructuralType parentType = property.DeclaringType;
            Type parentClrType = EntityDataSourceUtil.GetClrType(ocWorkspace, parentType); 
            this.propertyInfo = EntityDataSourceUtil.GetPropertyInfo(parentClrType, this.property.Name); 
        } 
         ///  
        /// Describes the member path in the form 'property1.property2...'. Use to
        /// determine display name for nested properties in the EDSC.
        ///  
        /// Description of the   
        internal string GetDescription()
        { 
            string prefix = null == this.parent ? string.Empty : this.parent.GetDescription() + "."; 
            return prefix + this.property.Name;
        } 
        /// 
        /// Indicates whether original values of this member should be preserved.
        ///   
        internal bool IsInteresting
        { 
            get 
            {
                // a member path is interesting if anything along the path is interesting 
                return this.isLocallyInteresting || (null != this.parent && this.parent.IsInteresting);
            }
        }
 
        /// 
        /// Indicates whether this member represents a primary key value. 
        ///   
        internal bool IsKey
        { 
            get { return this.isKey; }
        }
        ///  
        /// Indicates whether this member can be assigned a value of null.
        ///   
        internal bool IsNullable 
        {
            get { return this.property.Nullable; } 
        }
        internal bool IsPrimitive
        { 
            get { return this.property.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType; }
        } 
 
        /// 
        /// Gets the CLR type of the last member in the path. 
        ///  
        internal Type ClrType
        {
            get { return this.clrType; } 
        }
 
        internal object GetValue(object entity) 
        {
            object parentObjectValue = GetParentObjectValue(entity, false /* initialize */); 
            if (null == parentObjectValue)
            {
                // use convention that property of null is null
                return null; 
            }
            else 
            { 
                // get this property
                object propertyValue = this.propertyInfo.GetValue(parentObjectValue, new object[] { }); 
                return propertyValue;
            }
        } 
        internal void SetValue(object entity, object value) 
        { 
            object parentObjectValue = GetParentObjectValue(entity, true /* initialize */);
 
            // set property value on parent
            this.propertyInfo.SetValue(parentObjectValue, value, new object[] { });
        }
 
        private object Initialize(object entity)
        { 
            // get parent's value 
            object parentObjectValue = GetParentObjectValue(entity, true /* initialize */);
 
            // construct type instance for this property
            object propertyValue = EntityDataSourceUtil.InitializeType(this.ClrType);
            // set property 
            this.propertyInfo.SetValue(parentObjectValue, propertyValue, new object[] { });
 
            return propertyValue; 
        }
 
        private object GetParentObjectValue(object entity, bool initialize)
        {
            // get parent's value
            object parentObjectValue; 
            if (null == this.parent) 
            { 
                // at the top level, the entity is the value
                parentObjectValue = entity; 
            }
            else
            {
                parentObjectValue = this.parent.GetValue(entity); 
                if (null == parentObjectValue && initialize) 
                { 
                    parentObjectValue = this.parent.Initialize(entity);
                } 
            }
            return parentObjectValue;
        } 
        internal string GetEntitySqlValue() 
        { 
            // it.[member1].[member2]...
            string prefix; 
            if (null != parent)
            {
                prefix = parent.GetEntitySqlValue(); 
            }
            else 
            { 
                prefix = EntityDataSourceUtil.EntitySqlElementAlias;
            } 
            string eSql = prefix + "." + EntityDataSourceUtil.QuoteEntitySqlIdentifier(this.property.Name);
            return eSql; 
        }
 
        private bool IsPropertyAKey(EdmProperty property) 
        {
            bool isKey = false; 
            EntityType entityType = property.DeclaringType as EntityType;
            if (null != entityType)
            {
                isKey = entityType.KeyMembers.Contains(property); 
            }
            return isKey; 
        } 
        public override string ToString() 
        {
            string prefix = null == this.parent ? string.Empty : this.parent.ToString() + "->";
            return prefix + this.property.Name;
        } 
    }
} 
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        
                        
                        
                        
                    Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- KeyedCollection.cs
- CultureTable.cs
- XsdDataContractExporter.cs
- LogicalTreeHelper.cs
- SharedTcpTransportManager.cs
- DataGridTable.cs
- DataRecordInfo.cs
- XmlQueryOutput.cs
- SettingsPropertyCollection.cs
- counter.cs
- ControlCommandSet.cs
- ConfigXmlWhitespace.cs
- SqlInternalConnectionTds.cs
- ScriptManager.cs
- XomlCompilerResults.cs
- MobileUserControlDesigner.cs
- Point4DConverter.cs
- PointCollectionValueSerializer.cs
- Configuration.cs
- Renderer.cs
- ReferencedAssembly.cs
- ErrorInfoXmlDocument.cs
- PageContent.cs
- ChangeProcessor.cs
- TextContainerChangeEventArgs.cs
- QueryRewriter.cs
- ActivityScheduledQuery.cs
- FlowStep.cs
- StoryFragments.cs
- ReferenceConverter.cs
- HostSecurityManager.cs
- ExtendedPropertyDescriptor.cs
- FileNotFoundException.cs
- FtpWebRequest.cs
- QilIterator.cs
- IsolatedStorage.cs
- StackSpiller.cs
- FixedStringLookup.cs
- HyperLinkColumn.cs
- TextDecorationCollection.cs
- ButtonFlatAdapter.cs
- TextMetrics.cs
- TextDecoration.cs
- DictionaryGlobals.cs
- DataMemberListEditor.cs
- IgnoreSectionHandler.cs
- ContentElementAutomationPeer.cs
- DataBinder.cs
- BinarySerializer.cs
- CursorInteropHelper.cs
- TabletCollection.cs
- TreeNodeCollection.cs
- TagElement.cs
- UTF7Encoding.cs
- ConfigsHelper.cs
- WorkflowView.cs
- XamlReaderHelper.cs
- AsymmetricSignatureFormatter.cs
- ComboBoxRenderer.cs
- FixedSOMLineRanges.cs
- RelationshipType.cs
- listviewsubitemcollectioneditor.cs
- RightsManagementPermission.cs
- EndpointConfigContainer.cs
- Single.cs
- KeyGestureValueSerializer.cs
- ProfileSettings.cs
- DiscoveryReferences.cs
- Matrix3DConverter.cs
- TimeIntervalCollection.cs
- WSSecurityPolicy11.cs
- EditorPartChrome.cs
- ElementMarkupObject.cs
- GeometryDrawing.cs
- StyleTypedPropertyAttribute.cs
- UrlMappingCollection.cs
- _NegoStream.cs
- StateWorkerRequest.cs
- WindowsListViewItemCheckBox.cs
- StylusDevice.cs
- TableRowGroup.cs
- Baml2006KeyRecord.cs
- ApplicationServiceManager.cs
- CommandHelper.cs
- ButtonBaseDesigner.cs
- ImageAttributes.cs
- RootBuilder.cs
- AuthenticationModuleElementCollection.cs
- DataBoundControlActionList.cs
- DockPattern.cs
- AgileSafeNativeMemoryHandle.cs
- DynamicDataExtensions.cs
- CodeComment.cs
- Pens.cs
- BinHexDecoder.cs
- BamlLocalizer.cs
- LockRecursionException.cs
- BitArray.cs
- ObjectQueryExecutionPlan.cs
- ListSortDescription.cs