Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Objects / ObjectViewEntityCollectionData.cs / 1305376 / ObjectViewEntityCollectionData.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Objects.DataClasses;
using System.Data.Objects.Internal;
using System.Diagnostics;
using System.Data.Common;
namespace System.Data.Objects
{
///
/// Manages a binding list constructed from an EntityCollection.
///
///
/// Type of the elements in the binding list.
///
///
/// Type of element in the underlying EntityCollection.
///
///
/// The binding list is initialized from the EntityCollection,
/// and is synchronized with changes made to the EntityCollection membership.
/// This class always allows additions and removals from the binding list.
///
internal sealed class ObjectViewEntityCollectionData : IObjectViewData
where TItemElement : class
where TViewElement : TItemElement
{
private List _bindingList;
private EntityCollection _entityCollection;
private readonly bool _canEditItems;
///
/// True if item that was added to binding list but not underlying entity collection
/// is now being committed to the collection.
/// Otherwise false.
/// Used by CommitItemAt and OnCollectionChanged methods to coordinate addition
/// of new item to underlying entity collection.
///
private bool _itemCommitPending;
///
/// Construct a new instance of the ObjectViewEntityCollectionData class using the supplied entityCollection.
///
///
/// EntityCollection used to populate the binding list.
///
internal ObjectViewEntityCollectionData(EntityCollection entityCollection)
{
_entityCollection = entityCollection;
_canEditItems = true;
// Allow deferred loading to occur when initially populating the collection
_bindingList = new List(entityCollection.Count);
foreach (TViewElement entity in entityCollection)
{
_bindingList.Add(entity);
}
}
#region IObjectViewData Members
public IList List
{
get { return _bindingList; }
}
public bool AllowNew
{
get { return !_entityCollection.IsReadOnly; }
}
public bool AllowEdit
{
get { return _canEditItems; }
}
public bool AllowRemove
{
get { return !_entityCollection.IsReadOnly; }
}
public bool FiresEventOnAdd
{
get { return true; }
}
public bool FiresEventOnRemove
{
get { return true; }
}
public bool FiresEventOnClear
{
get { return true; }
}
public void EnsureCanAddNew()
{
// nop
}
public int Add(TViewElement item, bool isAddNew)
{
if (isAddNew)
{
// Item is added to bindingList, but pending addition to entity collection.
_bindingList.Add(item);
}
else
{
_entityCollection.Add(item);
// OnCollectionChanged will be fired, where the binding list will be updated.
}
return _bindingList.Count - 1;
}
public void CommitItemAt(int index)
{
TViewElement item = _bindingList[index];
try
{
_itemCommitPending = true;
_entityCollection.Add(item);
// OnCollectionChanged will be fired, where the binding list will be updated.
}
finally
{
_itemCommitPending = false;
}
}
public void Clear()
{
if (0 < _bindingList.Count)
{
List
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RedirectionProxy.cs
- ImageSource.cs
- DataGridViewCellCancelEventArgs.cs
- RecordBuilder.cs
- CommandEventArgs.cs
- ChannelDispatcherCollection.cs
- WCFBuildProvider.cs
- GridView.cs
- Gdiplus.cs
- SafeFileMappingHandle.cs
- SynchronizationLockException.cs
- CharAnimationUsingKeyFrames.cs
- SettingsPropertyWrongTypeException.cs
- SmiContext.cs
- CreateUserWizardDesigner.cs
- EntitySqlQueryCacheEntry.cs
- _Semaphore.cs
- BuildProvidersCompiler.cs
- DriveInfo.cs
- SequenceRangeCollection.cs
- RectAnimationBase.cs
- SystemIPGlobalProperties.cs
- MonikerUtility.cs
- ToolboxItemCollection.cs
- ButtonChrome.cs
- HtmlControl.cs
- EventSinkActivity.cs
- DrawingState.cs
- XmlSignificantWhitespace.cs
- SelectionRangeConverter.cs
- FixedSOMTableCell.cs
- AutomationElement.cs
- DesignerPerfEventProvider.cs
- DocumentSequenceHighlightLayer.cs
- TransformGroup.cs
- BookmarkScope.cs
- TreeNodeStyleCollection.cs
- PartialArray.cs
- TypeDelegator.cs
- AuthenticationService.cs
- StringComparer.cs
- ChannelParameterCollection.cs
- ListItemConverter.cs
- ChannelSinkStacks.cs
- ProxyWebPartManager.cs
- ObjectNotFoundException.cs
- SafeEventLogWriteHandle.cs
- DataServiceKeyAttribute.cs
- LockRecursionException.cs
- StatusInfoItem.cs
- XpsLiterals.cs
- ProxyWebPartManager.cs
- CheckBox.cs
- TextServicesContext.cs
- StyleBamlRecordReader.cs
- WebBrowserBase.cs
- RegisteredDisposeScript.cs
- Span.cs
- TdsParserSafeHandles.cs
- SafeFileMappingHandle.cs
- RegexMatchCollection.cs
- EventLogPermissionEntry.cs
- CompositeFontFamily.cs
- Scheduling.cs
- StoreContentChangedEventArgs.cs
- CompensableActivity.cs
- XmlSchemaComplexType.cs
- DbParameterCollectionHelper.cs
- CatalogZoneDesigner.cs
- ListenerElementsCollection.cs
- CodeCommentStatement.cs
- FullTrustAssembliesSection.cs
- CompilerWrapper.cs
- XmlDictionaryWriter.cs
- PrefixQName.cs
- ListViewPagedDataSource.cs
- DbConnectionPoolGroupProviderInfo.cs
- TryExpression.cs
- DataIdProcessor.cs
- XslAstAnalyzer.cs
- DesignerAdRotatorAdapter.cs
- SmtpFailedRecipientsException.cs
- ZipIOExtraFieldPaddingElement.cs
- NotFiniteNumberException.cs
- ParameterToken.cs
- LogEntrySerializationException.cs
- ActiveDocumentEvent.cs
- StaticSiteMapProvider.cs
- CheckBox.cs
- SigningDialog.cs
- CompareInfo.cs
- StatusBarDrawItemEvent.cs
- Stream.cs
- Figure.cs
- formatter.cs
- Debug.cs
- _DigestClient.cs
- XmlStreamNodeWriter.cs
- Signature.cs
- ImmutableObjectAttribute.cs