Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Common / CommandTrees / Internal / ExpressionList.cs / 2 / ExpressionList.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....], [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.Data.Common; using System.Data.Metadata.Edm; using System.Data.Common.CommandTrees; namespace System.Data.Common.CommandTrees.Internal { internal class ExpressionList : IList{ private string _name; private DbCommandTree _commandTree; private List _list; private ExpressionList(string name, DbCommandTree owner) { _name = name; _commandTree = owner; } internal List ExpressionLinks { get { return _list; } } internal ExpressionList(string name, DbCommandTree owner, int capacity) : this(name, owner) { _list = new List (capacity); for(int idx = 0; idx < capacity; idx++) { _list.Add(new ExpressionLink(CommandTreeUtils.FormatIndex(_name, idx), owner)); } } internal ExpressionList(string name, DbCommandTree owner, IList args) : this(name, owner) { Debug.Assert(args != null, "Argument list is null?"); int capacity = args.Count; List list = new List (capacity); for (int idx = 0; idx < capacity; idx++) { list.Add(new ExpressionLink(CommandTreeUtils.FormatIndex(_name, idx), _commandTree, args[idx])); } _list = list; } internal ExpressionList(string name, DbCommandTree owner, TypeUsage expectedElementType, IList args) : this(name, owner) { Debug.Assert(args != null, "Argument list is null?"); int capacity = args.Count; List list = new List (capacity); for (int idx = 0; idx < capacity; idx++) { list.Add(new ExpressionLink(CommandTreeUtils.FormatIndex(_name, idx), _commandTree, expectedElementType, args[idx])); } _list = list; } internal ExpressionList(string name, DbCommandTree owner, PrimitiveTypeKind expectedElementPrimitiveType, IList args) : this(name, owner) { Debug.Assert(args != null, "Argument list is null?"); int capacity = args.Count; List list = new List (capacity); for (int idx = 0; idx < capacity; idx++) { list.Add(new ExpressionLink(CommandTreeUtils.FormatIndex(_name, idx), _commandTree, expectedElementPrimitiveType, args[idx])); } _list = list; } // // Called by DbFunctionAggregate and DbFunctionExpression // internal ExpressionList(string name, DbCommandTree owner, ReadOnlyMetadataCollection paramInfo, IList args) : this(name, owner) { int capacity = paramInfo.Count; List list = new List (capacity); for (int idx = 0; idx < capacity; idx++) { string elemName = CommandTreeUtils.FormatIndex(_name, idx); FunctionParameter paramMeta = paramInfo[idx]; _commandTree.TypeHelper.CheckParameter(paramMeta, elemName); list.Add(new ExpressionLink(elemName, _commandTree, paramMeta.TypeUsage)); } _list = list; this.SetElements(args); } internal ExpressionList(string name, DbCommandTree owner, IBaseList members, IList args) : this(name, owner) { _list = new List (); int idx = 0; foreach (EdmMember memberMeta in members) { string elemName = CommandTreeUtils.FormatIndex(_name, idx++); _commandTree.TypeHelper.CheckMember(memberMeta, elemName); _list.Add(new ExpressionLink(elemName, _commandTree, Helper.GetModelTypeUsage(memberMeta))); } this.SetElements(args); } /// /// Sets the value of each element in the list without instructing /// the owning Command Tree to consider itself 'modified'. /// Should only be used to set initial values for the list elements, /// and not called again after that initialization has taken place /// (otherwise the Command Tree's VersionNumber property will not be /// updated even though changes have been made to the list). /// /// The DbExpression values to use as list elements. Must match the expected count of this list. internal void SetElements(IListargs) { int addedCount = 0; for(int idx = 0; idx < args.Count; idx++) { if (idx > _list.Count - 1) { throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_ExpressionList_IncorrectElementCount, _name); } _list[idx].InitializeValue(args[idx]); addedCount++; } if (addedCount != _list.Count) { throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_ExpressionList_IncorrectElementCount, _name); } } internal void SetExpectedElementType(TypeUsage type) { foreach (ExpressionLink link in _list) { link.SetExpectedType(type); } } internal TypeUsage GetCommonElementType() { TypeUsage commonType = null; foreach (ExpressionLink exprLink in _list) { if (null == commonType) { commonType = exprLink.Expression.ResultType; } else { commonType = TypeHelpers.GetCommonTypeUsage(commonType, exprLink.Expression.ResultType); } if (null == commonType) { break; } } return commonType; } internal void SetAt(int index, DbExpression value) { _list[index].Expression = value; } #region IList Members int IList .IndexOf(DbExpression item) { for (int idx = 0; idx < _list.Count; idx++) { if (_list[idx].Expression == item) { return idx; } } return -1; } void IList .Insert(int index, DbExpression item) { throw EntityUtil.NotSupported(); } void IList .RemoveAt(int index) { throw EntityUtil.NotSupported(); } DbExpression IList .this[int index] { get { return _list[index].Expression; } #if MUTABLE_CQT set { _list[index].Expression = value; } #else set { throw EntityUtil.NotSupported(); } #endif } #endregion #region ICollection Members void ICollection .Add(DbExpression item) { throw EntityUtil.NotSupported(); } void ICollection .Clear() { throw EntityUtil.NotSupported(); } bool ICollection .Contains(DbExpression item) { return (((IList )this).IndexOf(item) > -1); } void ICollection .CopyTo(DbExpression[] array, int arrayIndex) { List exprs = new List (); foreach (ExpressionLink exprLink in _list) { exprs.Add(exprLink.Expression); } exprs.CopyTo(array, arrayIndex); } int ICollection .Count { get { return _list.Count; } } bool ICollection .IsReadOnly { #if MUTABLE_CQT get { return false; } #else get { return true; } #endif } bool ICollection .Remove(DbExpression item) { throw EntityUtil.NotSupported(); } #endregion #region IEnumerable Members IEnumerator IEnumerable .GetEnumerator() { return new ExpressionListEnumerator(_list.GetEnumerator()); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return ((IEnumerable )this).GetEnumerator(); } #endregion #region Nested Enumerator class private class ExpressionListEnumerator : IEnumerator { private IEnumerator m_Enumerator; internal ExpressionListEnumerator(IEnumerator innerEnum) { this.m_Enumerator = innerEnum; } #region IEnumerator Members DbExpression IEnumerator .Current { get { return this.m_Enumerator.Current.Expression; } } #endregion #region IDisposable Members void IDisposable.Dispose() { this.m_Enumerator.Dispose(); } #endregion #region IEnumerator Members object System.Collections.IEnumerator.Current { get { return this.m_Enumerator.Current.Expression; } } bool System.Collections.IEnumerator.MoveNext() { return this.m_Enumerator.MoveNext(); } void System.Collections.IEnumerator.Reset() { this.m_Enumerator.Reset(); } #endregion } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....], [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.Data.Common; using System.Data.Metadata.Edm; using System.Data.Common.CommandTrees; namespace System.Data.Common.CommandTrees.Internal { internal class ExpressionList : IList{ private string _name; private DbCommandTree _commandTree; private List _list; private ExpressionList(string name, DbCommandTree owner) { _name = name; _commandTree = owner; } internal List ExpressionLinks { get { return _list; } } internal ExpressionList(string name, DbCommandTree owner, int capacity) : this(name, owner) { _list = new List (capacity); for(int idx = 0; idx < capacity; idx++) { _list.Add(new ExpressionLink(CommandTreeUtils.FormatIndex(_name, idx), owner)); } } internal ExpressionList(string name, DbCommandTree owner, IList args) : this(name, owner) { Debug.Assert(args != null, "Argument list is null?"); int capacity = args.Count; List list = new List (capacity); for (int idx = 0; idx < capacity; idx++) { list.Add(new ExpressionLink(CommandTreeUtils.FormatIndex(_name, idx), _commandTree, args[idx])); } _list = list; } internal ExpressionList(string name, DbCommandTree owner, TypeUsage expectedElementType, IList args) : this(name, owner) { Debug.Assert(args != null, "Argument list is null?"); int capacity = args.Count; List list = new List (capacity); for (int idx = 0; idx < capacity; idx++) { list.Add(new ExpressionLink(CommandTreeUtils.FormatIndex(_name, idx), _commandTree, expectedElementType, args[idx])); } _list = list; } internal ExpressionList(string name, DbCommandTree owner, PrimitiveTypeKind expectedElementPrimitiveType, IList args) : this(name, owner) { Debug.Assert(args != null, "Argument list is null?"); int capacity = args.Count; List list = new List (capacity); for (int idx = 0; idx < capacity; idx++) { list.Add(new ExpressionLink(CommandTreeUtils.FormatIndex(_name, idx), _commandTree, expectedElementPrimitiveType, args[idx])); } _list = list; } // // Called by DbFunctionAggregate and DbFunctionExpression // internal ExpressionList(string name, DbCommandTree owner, ReadOnlyMetadataCollection paramInfo, IList args) : this(name, owner) { int capacity = paramInfo.Count; List list = new List (capacity); for (int idx = 0; idx < capacity; idx++) { string elemName = CommandTreeUtils.FormatIndex(_name, idx); FunctionParameter paramMeta = paramInfo[idx]; _commandTree.TypeHelper.CheckParameter(paramMeta, elemName); list.Add(new ExpressionLink(elemName, _commandTree, paramMeta.TypeUsage)); } _list = list; this.SetElements(args); } internal ExpressionList(string name, DbCommandTree owner, IBaseList members, IList args) : this(name, owner) { _list = new List (); int idx = 0; foreach (EdmMember memberMeta in members) { string elemName = CommandTreeUtils.FormatIndex(_name, idx++); _commandTree.TypeHelper.CheckMember(memberMeta, elemName); _list.Add(new ExpressionLink(elemName, _commandTree, Helper.GetModelTypeUsage(memberMeta))); } this.SetElements(args); } /// /// Sets the value of each element in the list without instructing /// the owning Command Tree to consider itself 'modified'. /// Should only be used to set initial values for the list elements, /// and not called again after that initialization has taken place /// (otherwise the Command Tree's VersionNumber property will not be /// updated even though changes have been made to the list). /// /// The DbExpression values to use as list elements. Must match the expected count of this list. internal void SetElements(IListargs) { int addedCount = 0; for(int idx = 0; idx < args.Count; idx++) { if (idx > _list.Count - 1) { throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_ExpressionList_IncorrectElementCount, _name); } _list[idx].InitializeValue(args[idx]); addedCount++; } if (addedCount != _list.Count) { throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_ExpressionList_IncorrectElementCount, _name); } } internal void SetExpectedElementType(TypeUsage type) { foreach (ExpressionLink link in _list) { link.SetExpectedType(type); } } internal TypeUsage GetCommonElementType() { TypeUsage commonType = null; foreach (ExpressionLink exprLink in _list) { if (null == commonType) { commonType = exprLink.Expression.ResultType; } else { commonType = TypeHelpers.GetCommonTypeUsage(commonType, exprLink.Expression.ResultType); } if (null == commonType) { break; } } return commonType; } internal void SetAt(int index, DbExpression value) { _list[index].Expression = value; } #region IList Members int IList .IndexOf(DbExpression item) { for (int idx = 0; idx < _list.Count; idx++) { if (_list[idx].Expression == item) { return idx; } } return -1; } void IList .Insert(int index, DbExpression item) { throw EntityUtil.NotSupported(); } void IList .RemoveAt(int index) { throw EntityUtil.NotSupported(); } DbExpression IList .this[int index] { get { return _list[index].Expression; } #if MUTABLE_CQT set { _list[index].Expression = value; } #else set { throw EntityUtil.NotSupported(); } #endif } #endregion #region ICollection Members void ICollection .Add(DbExpression item) { throw EntityUtil.NotSupported(); } void ICollection .Clear() { throw EntityUtil.NotSupported(); } bool ICollection .Contains(DbExpression item) { return (((IList )this).IndexOf(item) > -1); } void ICollection .CopyTo(DbExpression[] array, int arrayIndex) { List exprs = new List (); foreach (ExpressionLink exprLink in _list) { exprs.Add(exprLink.Expression); } exprs.CopyTo(array, arrayIndex); } int ICollection .Count { get { return _list.Count; } } bool ICollection .IsReadOnly { #if MUTABLE_CQT get { return false; } #else get { return true; } #endif } bool ICollection .Remove(DbExpression item) { throw EntityUtil.NotSupported(); } #endregion #region IEnumerable Members IEnumerator IEnumerable .GetEnumerator() { return new ExpressionListEnumerator(_list.GetEnumerator()); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return ((IEnumerable )this).GetEnumerator(); } #endregion #region Nested Enumerator class private class ExpressionListEnumerator : IEnumerator { private IEnumerator m_Enumerator; internal ExpressionListEnumerator(IEnumerator innerEnum) { this.m_Enumerator = innerEnum; } #region IEnumerator Members DbExpression IEnumerator .Current { get { return this.m_Enumerator.Current.Expression; } } #endregion #region IDisposable Members void IDisposable.Dispose() { this.m_Enumerator.Dispose(); } #endregion #region IEnumerator Members object System.Collections.IEnumerator.Current { get { return this.m_Enumerator.Current.Expression; } } bool System.Collections.IEnumerator.MoveNext() { return this.m_Enumerator.MoveNext(); } void System.Collections.IEnumerator.Reset() { this.m_Enumerator.Reset(); } #endregion } #endregion } } // 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
- TypeSystem.cs
- ObjectResult.cs
- KeyInstance.cs
- IdentifierCollection.cs
- BaseTypeViewSchema.cs
- OleDbParameterCollection.cs
- TextEmbeddedObject.cs
- IIS7WorkerRequest.cs
- TrustLevelCollection.cs
- ValidationVisibilityAttribute.cs
- BrushConverter.cs
- DrawingBrush.cs
- Listen.cs
- TableLayoutSettingsTypeConverter.cs
- ViewBox.cs
- ResXResourceWriter.cs
- IndexedEnumerable.cs
- BuildResult.cs
- ChildrenQuery.cs
- CheckBox.cs
- OpenTypeLayout.cs
- XmlnsCache.cs
- CustomLineCap.cs
- InvalidAsynchronousStateException.cs
- ListViewItemCollectionEditor.cs
- WebServiceReceiveDesigner.cs
- Query.cs
- NameValuePair.cs
- DataControlFieldHeaderCell.cs
- EventLogLink.cs
- IBuiltInEvidence.cs
- WindowsEditBox.cs
- SynchronizedInputAdaptor.cs
- CharEntityEncoderFallback.cs
- InvokePatternIdentifiers.cs
- SslStream.cs
- RoutedUICommand.cs
- ClientData.cs
- ParameterCollection.cs
- ResourceAttributes.cs
- DesignerAutoFormat.cs
- DiagnosticsConfigurationHandler.cs
- CommandBindingCollection.cs
- LogConverter.cs
- BaseDataBoundControl.cs
- MdImport.cs
- SynchronousChannel.cs
- HttpFileCollection.cs
- TextEncodedRawTextWriter.cs
- ConnectionPoint.cs
- Help.cs
- ErrorLog.cs
- XmlSerializableReader.cs
- LinkArea.cs
- PassportPrincipal.cs
- safemediahandle.cs
- Message.cs
- RequiredAttributeAttribute.cs
- SqlCommand.cs
- DesignerProperties.cs
- Int32AnimationBase.cs
- WindowsToolbarItemAsMenuItem.cs
- ResourceKey.cs
- ColorMap.cs
- wgx_commands.cs
- cryptoapiTransform.cs
- BooleanToSelectiveScrollingOrientationConverter.cs
- HttpWebResponse.cs
- SchemaExporter.cs
- SoapIncludeAttribute.cs
- PowerModeChangedEventArgs.cs
- ProxyWebPart.cs
- SafeTokenHandle.cs
- XamlTypeMapper.cs
- KeyValueConfigurationElement.cs
- ContextStaticAttribute.cs
- EntityContainerAssociationSetEnd.cs
- BufferModesCollection.cs
- ToolBarPanel.cs
- MappingModelBuildProvider.cs
- ConfigXmlCDataSection.cs
- SeparatorAutomationPeer.cs
- DbProviderServices.cs
- _FixedSizeReader.cs
- ObjectListFieldsPage.cs
- ResolveNameEventArgs.cs
- WindowClosedEventArgs.cs
- AsymmetricAlgorithm.cs
- ImpersonationContext.cs
- ColorMap.cs
- Wizard.cs
- RoleGroupCollection.cs
- SafeThemeHandle.cs
- XmlHierarchyData.cs
- DbMetaDataColumnNames.cs
- CorrelationActionMessageFilter.cs
- ByeOperationCD1AsyncResult.cs
- SqlUdtInfo.cs
- UInt32Storage.cs
- AnnotationHelper.cs