Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / Microsoft / Scripting / Ast / ListArgumentProvider.cs / 1305376 / ListArgumentProvider.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;
using System.Collections.Generic;
using System.Text;
using System.Linq.Expressions;
using System.Dynamic.Utils;
namespace System.Linq.Expressions {
///
/// Provides a wrapper around an IArgumentProvider which exposes the argument providers
/// members out as an IList of Expression. This is used to avoid allocating an array
/// which needs to be stored inside of a ReadOnlyCollection. Instead this type has
/// the same amount of overhead as an array without duplicating the storage of the
/// elements. This ensures that internally we can avoid creating and copying arrays
/// while users of the Expression trees also don't pay a size penalty for this internal
/// optimization. See IArgumentProvider for more general information on the Expression
/// tree optimizations being used here.
///
class ListArgumentProvider : IList {
private readonly IArgumentProvider _provider;
private readonly Expression _arg0;
internal ListArgumentProvider(IArgumentProvider provider, Expression arg0) {
_provider = provider;
_arg0 = arg0;
}
#region IList Members
public int IndexOf(Expression item) {
if (_arg0 == item) {
return 0;
}
for (int i = 1; i < _provider.ArgumentCount; i++) {
if (_provider.GetArgument(i) == item) {
return i;
}
}
return -1;
}
public void Insert(int index, Expression item) {
throw ContractUtils.Unreachable;
}
public void RemoveAt(int index) {
throw ContractUtils.Unreachable;
}
public Expression this[int index] {
get {
if (index == 0) {
return _arg0;
}
return _provider.GetArgument(index);
}
set {
throw ContractUtils.Unreachable;
}
}
#endregion
#region ICollection Members
public void Add(Expression item) {
throw ContractUtils.Unreachable;
}
public void Clear() {
throw ContractUtils.Unreachable;
}
public bool Contains(Expression item) {
return IndexOf(item) != -1;
}
public void CopyTo(Expression[] array, int arrayIndex) {
array[arrayIndex++] = _arg0;
for (int i = 1; i < _provider.ArgumentCount; i++) {
array[arrayIndex++] = _provider.GetArgument(i);
}
}
public int Count {
get { return _provider.ArgumentCount; }
}
public bool IsReadOnly {
get { return true; }
}
public bool Remove(Expression item) {
throw ContractUtils.Unreachable;
}
#endregion
#region IEnumerable Members
public IEnumerator GetEnumerator() {
yield return _arg0;
for (int i = 1; i < _provider.ArgumentCount; i++) {
yield return _provider.GetArgument(i);
}
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
yield return _arg0;
for (int i = 1; i < _provider.ArgumentCount; i++) {
yield return _provider.GetArgument(i);
}
}
#endregion
}
}
// 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;
using System.Collections.Generic;
using System.Text;
using System.Linq.Expressions;
using System.Dynamic.Utils;
namespace System.Linq.Expressions {
///
/// Provides a wrapper around an IArgumentProvider which exposes the argument providers
/// members out as an IList of Expression. This is used to avoid allocating an array
/// which needs to be stored inside of a ReadOnlyCollection. Instead this type has
/// the same amount of overhead as an array without duplicating the storage of the
/// elements. This ensures that internally we can avoid creating and copying arrays
/// while users of the Expression trees also don't pay a size penalty for this internal
/// optimization. See IArgumentProvider for more general information on the Expression
/// tree optimizations being used here.
///
class ListArgumentProvider : IList {
private readonly IArgumentProvider _provider;
private readonly Expression _arg0;
internal ListArgumentProvider(IArgumentProvider provider, Expression arg0) {
_provider = provider;
_arg0 = arg0;
}
#region IList Members
public int IndexOf(Expression item) {
if (_arg0 == item) {
return 0;
}
for (int i = 1; i < _provider.ArgumentCount; i++) {
if (_provider.GetArgument(i) == item) {
return i;
}
}
return -1;
}
public void Insert(int index, Expression item) {
throw ContractUtils.Unreachable;
}
public void RemoveAt(int index) {
throw ContractUtils.Unreachable;
}
public Expression this[int index] {
get {
if (index == 0) {
return _arg0;
}
return _provider.GetArgument(index);
}
set {
throw ContractUtils.Unreachable;
}
}
#endregion
#region ICollection Members
public void Add(Expression item) {
throw ContractUtils.Unreachable;
}
public void Clear() {
throw ContractUtils.Unreachable;
}
public bool Contains(Expression item) {
return IndexOf(item) != -1;
}
public void CopyTo(Expression[] array, int arrayIndex) {
array[arrayIndex++] = _arg0;
for (int i = 1; i < _provider.ArgumentCount; i++) {
array[arrayIndex++] = _provider.GetArgument(i);
}
}
public int Count {
get { return _provider.ArgumentCount; }
}
public bool IsReadOnly {
get { return true; }
}
public bool Remove(Expression item) {
throw ContractUtils.Unreachable;
}
#endregion
#region IEnumerable Members
public IEnumerator GetEnumerator() {
yield return _arg0;
for (int i = 1; i < _provider.ArgumentCount; i++) {
yield return _provider.GetArgument(i);
}
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
yield return _arg0;
for (int i = 1; i < _provider.ArgumentCount; i++) {
yield return _provider.GetArgument(i);
}
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CacheAxisQuery.cs
- TableRow.cs
- DbParameterCollection.cs
- _BaseOverlappedAsyncResult.cs
- DrawListViewItemEventArgs.cs
- ComponentSerializationService.cs
- BitmapEncoder.cs
- PathParser.cs
- WSHttpBindingCollectionElement.cs
- COM2TypeInfoProcessor.cs
- IntSecurity.cs
- CompositionTarget.cs
- WebEventTraceProvider.cs
- KeyboardNavigation.cs
- WebPartConnectionsEventArgs.cs
- RequestCache.cs
- ContractNamespaceAttribute.cs
- EditingScopeUndoUnit.cs
- DataTemplateSelector.cs
- SmtpFailedRecipientException.cs
- EntityProxyFactory.cs
- AnnotationHelper.cs
- InheritanceContextChangedEventManager.cs
- XmlSchemaExporter.cs
- _NestedSingleAsyncResult.cs
- EmptyEnumerator.cs
- OdbcConnectionHandle.cs
- NotImplementedException.cs
- PathFigure.cs
- SystemIPv6InterfaceProperties.cs
- ResourcePermissionBaseEntry.cs
- XamlTypeMapper.cs
- DocumentOrderQuery.cs
- SoapReflectionImporter.cs
- EntityDataSourceChangingEventArgs.cs
- XAMLParseException.cs
- StatusBar.cs
- ping.cs
- WindowsTooltip.cs
- Enum.cs
- ScrollContentPresenter.cs
- CustomValidator.cs
- InitializationEventAttribute.cs
- WindowShowOrOpenTracker.cs
- HtmlContainerControl.cs
- UnsafeNativeMethods.cs
- UrlAuthorizationModule.cs
- GeneralTransform2DTo3D.cs
- StorageInfo.cs
- BamlVersionHeader.cs
- ResourceContainer.cs
- Control.cs
- BookmarkInfo.cs
- TimersDescriptionAttribute.cs
- SmiRecordBuffer.cs
- DataObjectMethodAttribute.cs
- RawMouseInputReport.cs
- NotCondition.cs
- NaturalLanguageHyphenator.cs
- DocumentPageViewAutomationPeer.cs
- ProtocolElement.cs
- ObjectCache.cs
- HealthMonitoringSectionHelper.cs
- ImageSource.cs
- NoneExcludedImageIndexConverter.cs
- DistributedTransactionPermission.cs
- XamlPointCollectionSerializer.cs
- dtdvalidator.cs
- newinstructionaction.cs
- FastEncoderWindow.cs
- FlowDocumentPaginator.cs
- ToolboxItem.cs
- Double.cs
- ToolStripItemRenderEventArgs.cs
- ColumnResizeUndoUnit.cs
- DBCSCodePageEncoding.cs
- PrivilegedConfigurationManager.cs
- SmtpNtlmAuthenticationModule.cs
- HTMLTextWriter.cs
- HtmlTableRow.cs
- EntitySqlQueryCacheKey.cs
- DataGridViewCheckBoxColumn.cs
- KeyValueSerializer.cs
- Wizard.cs
- EncoderParameters.cs
- PeerNameRegistration.cs
- ChtmlPageAdapter.cs
- MessageFault.cs
- EmissiveMaterial.cs
- SafeHandle.cs
- NotSupportedException.cs
- ZipFileInfo.cs
- GridViewRowEventArgs.cs
- FragmentQuery.cs
- KeyPullup.cs
- CompilerError.cs
- BaseDataBoundControlDesigner.cs
- ContainerParagraph.cs
- DbParameterHelper.cs
- TraceContextEventArgs.cs