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
- DataGridViewCell.cs
- DataGridViewColumnStateChangedEventArgs.cs
- InlineObject.cs
- ComponentEditorPage.cs
- XmlSchemaInfo.cs
- ArithmeticException.cs
- RegistrationServices.cs
- RawStylusInputCustomData.cs
- TextInfo.cs
- ItemMap.cs
- SID.cs
- DataReceivedEventArgs.cs
- HTTPNotFoundHandler.cs
- SchemaMerger.cs
- EnumBuilder.cs
- NamespaceMapping.cs
- CreateUserWizardStep.cs
- ITreeGenerator.cs
- Matrix3DConverter.cs
- SRDisplayNameAttribute.cs
- MimeMultiPart.cs
- AsynchronousChannel.cs
- UserThread.cs
- QueryCursorEventArgs.cs
- CommandID.cs
- FramingDecoders.cs
- OneOf.cs
- DataGridViewButtonCell.cs
- EntityRecordInfo.cs
- TextDecorationCollectionConverter.cs
- ExceptionHandlers.cs
- ImageIndexConverter.cs
- BaseValidator.cs
- TextServicesPropertyRanges.cs
- listitem.cs
- SmiTypedGetterSetter.cs
- DispatcherExceptionFilterEventArgs.cs
- SplineQuaternionKeyFrame.cs
- DataGridTextBox.cs
- WinFormsSpinner.cs
- DataBoundControlHelper.cs
- MetadataSerializer.cs
- BatchParser.cs
- OpenFileDialog.cs
- WindowsListViewItemCheckBox.cs
- LongSumAggregationOperator.cs
- HtmlAnchor.cs
- PauseStoryboard.cs
- HandlerBase.cs
- OTFRasterizer.cs
- HostProtectionException.cs
- PeerNameRecordCollection.cs
- DateTimeOffsetConverter.cs
- TextSelectionHelper.cs
- RuleSettingsCollection.cs
- SQLConvert.cs
- DocumentViewerAutomationPeer.cs
- AbstractSvcMapFileLoader.cs
- UserNamePasswordValidationMode.cs
- RegexRunnerFactory.cs
- FacetChecker.cs
- DataGrid.cs
- HtmlHead.cs
- BookmarkWorkItem.cs
- ApplicationFileParser.cs
- TypeUsageBuilder.cs
- GeometryCombineModeValidation.cs
- XMLDiffLoader.cs
- ServiceReflector.cs
- VisualStyleInformation.cs
- Int32AnimationUsingKeyFrames.cs
- SchemaElement.cs
- ObjectDataSourceStatusEventArgs.cs
- MenuItem.cs
- ArrangedElementCollection.cs
- SecurityPolicySection.cs
- StringComparer.cs
- CodeCompileUnit.cs
- DataGridViewColumnEventArgs.cs
- AbstractDataSvcMapFileLoader.cs
- ZoneIdentityPermission.cs
- CompilationUtil.cs
- ToolStripItemTextRenderEventArgs.cs
- InstanceStore.cs
- DockPanel.cs
- Misc.cs
- ChannelHandler.cs
- EventLogSession.cs
- DataGridViewCellCancelEventArgs.cs
- DeploymentExceptionMapper.cs
- Token.cs
- WeakReferenceKey.cs
- CustomError.cs
- AspNetHostingPermission.cs
- GrammarBuilderBase.cs
- IListConverters.cs
- QilXmlReader.cs
- Rotation3DAnimationBase.cs
- CodePropertyReferenceExpression.cs
- DrawingBrush.cs