Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / Util / ObjectSet.cs / 1 / ObjectSet.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* ObjectSet class
*
* Copyright (c) 1999 Microsoft Corporation
*/
// Generics are causing perf regressions, so don't use them for now until we can figure
// it out (VSWhidbey 463572)
//#define USEGENERICSET
namespace System.Web.Util {
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
#if USEGENERICSET
/*
* Holds a set of unique objects of a specific type
*/
internal class ObjectSet : ICollection, ICollection {
protected const int StartingCapacity = 8;
private class EmptyEnumerator : IEnumerator {
object IEnumerator.Current { get { return null; } }
T IEnumerator.Current { get { return default(T); } }
bool IEnumerator.MoveNext() { return false; }
void IEnumerator.Reset() { }
void IDisposable.Dispose() { }
}
private static EmptyEnumerator _emptyEnumerator = new EmptyEnumerator();
private Dictionary _objects;
protected virtual Dictionary CreateDictionary() {
return new Dictionary(StartingCapacity);
}
public void AddCollection(ICollection c) {
foreach (T o in c) {
Add(o);
}
}
public void Add(T o) {
if (_objects == null) {
_objects = CreateDictionary();
}
_objects[o] = null;
}
public bool Remove(T o) {
if (_objects == null)
return false;
return _objects.Remove(o);
}
public bool Contains(T o) {
if (_objects == null)
return false;
return _objects.ContainsKey(o);
}
bool ICollection.IsReadOnly {
get {
return true;
}
}
public void Clear() {
if (_objects != null)
_objects.Clear();
}
IEnumerator IEnumerable.GetEnumerator() {
if (_objects == null)
return _emptyEnumerator;
return _objects.Keys.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
if (_objects == null)
return _emptyEnumerator;
return _objects.Keys.GetEnumerator();
}
public int Count {
get {
if (_objects == null)
return 0;
return _objects.Keys.Count;
}
}
void ICollection.CopyTo(T[] array, int index) {
if (_objects != null)
_objects.Keys.CopyTo(array, index);
}
bool ICollection.IsSynchronized {
get {
if (_objects == null)
return true;
return ((ICollection)_objects.Keys).IsSynchronized;
}
}
object ICollection.SyncRoot {
get {
if (_objects == null)
return this;
return ((ICollection)_objects.Keys).SyncRoot;
}
}
public void CopyTo(Array array, int index) {
if (_objects != null)
((ICollection)_objects.Keys).CopyTo(array, index);
}
}
internal class StringSet : ObjectSet { }
internal class CaseInsensitiveStringSet : StringSet {
protected override Dictionary CreateDictionary() {
return new Dictionary(StartingCapacity, StringComparer.InvariantCultureIgnoreCase);
}
}
internal class VirtualPathSet : ObjectSet { }
internal class AssemblySet : ObjectSet {
internal static AssemblySet Create(ICollection c) {
AssemblySet objectSet = new AssemblySet();
objectSet.AddCollection(c);
return objectSet;
}
}
internal class BuildProviderSet : ObjectSet { }
internal class ControlSet : ObjectSet { }
#else
/*
* Holds a set of unique objects
*/
internal class ObjectSet: ICollection {
private class EmptyEnumerator: IEnumerator {
public object Current { get { return null; } }
public bool MoveNext() { return false; }
public void Reset() {}
}
private static EmptyEnumerator _emptyEnumerator = new EmptyEnumerator();
private IDictionary _objects;
internal ObjectSet() {}
// By default, it's case sensitive
protected virtual bool CaseInsensitive { get { return false; } }
public void Add(object o) {
if (_objects == null)
_objects = new System.Collections.Specialized.HybridDictionary(CaseInsensitive);
_objects[o] = null;
}
public void AddCollection(ICollection c) {
foreach (object o in c) {
Add(o);
}
}
public void Remove(object o) {
if (_objects == null)
return;
_objects.Remove(o);
}
public bool Contains(object o) {
if (_objects == null)
return false;
return _objects.Contains(o);
}
IEnumerator IEnumerable.GetEnumerator() {
if (_objects == null)
return _emptyEnumerator;
return _objects.Keys.GetEnumerator();
}
public int Count {
get {
if (_objects == null)
return 0;
return _objects.Keys.Count;
}
}
bool ICollection.IsSynchronized {
get {
if (_objects == null)
return true;
return _objects.Keys.IsSynchronized;
}
}
object ICollection.SyncRoot {
get {
if (_objects == null)
return this;
return _objects.Keys.SyncRoot;
}
}
public void CopyTo(Array array, int index) {
if (_objects != null)
_objects.Keys.CopyTo(array, index);
}
}
internal class StringSet: ObjectSet {
internal StringSet() {}
}
internal class CaseInsensitiveStringSet: StringSet {
protected override bool CaseInsensitive { get { return true; } }
}
internal class VirtualPathSet : ObjectSet {
internal VirtualPathSet() { }
}
internal class AssemblySet : ObjectSet {
internal AssemblySet() { }
internal static AssemblySet Create(ICollection c) {
AssemblySet objectSet = new AssemblySet();
objectSet.AddCollection(c);
return objectSet;
}
}
internal class BuildProviderSet : ObjectSet {
internal BuildProviderSet() { }
}
internal class ControlSet : ObjectSet {
internal ControlSet() { }
}
#endif
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* ObjectSet class
*
* Copyright (c) 1999 Microsoft Corporation
*/
// Generics are causing perf regressions, so don't use them for now until we can figure
// it out (VSWhidbey 463572)
//#define USEGENERICSET
namespace System.Web.Util {
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
#if USEGENERICSET
/*
* Holds a set of unique objects of a specific type
*/
internal class ObjectSet : ICollection, ICollection {
protected const int StartingCapacity = 8;
private class EmptyEnumerator : IEnumerator {
object IEnumerator.Current { get { return null; } }
T IEnumerator.Current { get { return default(T); } }
bool IEnumerator.MoveNext() { return false; }
void IEnumerator.Reset() { }
void IDisposable.Dispose() { }
}
private static EmptyEnumerator _emptyEnumerator = new EmptyEnumerator();
private Dictionary _objects;
protected virtual Dictionary CreateDictionary() {
return new Dictionary(StartingCapacity);
}
public void AddCollection(ICollection c) {
foreach (T o in c) {
Add(o);
}
}
public void Add(T o) {
if (_objects == null) {
_objects = CreateDictionary();
}
_objects[o] = null;
}
public bool Remove(T o) {
if (_objects == null)
return false;
return _objects.Remove(o);
}
public bool Contains(T o) {
if (_objects == null)
return false;
return _objects.ContainsKey(o);
}
bool ICollection.IsReadOnly {
get {
return true;
}
}
public void Clear() {
if (_objects != null)
_objects.Clear();
}
IEnumerator IEnumerable.GetEnumerator() {
if (_objects == null)
return _emptyEnumerator;
return _objects.Keys.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
if (_objects == null)
return _emptyEnumerator;
return _objects.Keys.GetEnumerator();
}
public int Count {
get {
if (_objects == null)
return 0;
return _objects.Keys.Count;
}
}
void ICollection.CopyTo(T[] array, int index) {
if (_objects != null)
_objects.Keys.CopyTo(array, index);
}
bool ICollection.IsSynchronized {
get {
if (_objects == null)
return true;
return ((ICollection)_objects.Keys).IsSynchronized;
}
}
object ICollection.SyncRoot {
get {
if (_objects == null)
return this;
return ((ICollection)_objects.Keys).SyncRoot;
}
}
public void CopyTo(Array array, int index) {
if (_objects != null)
((ICollection)_objects.Keys).CopyTo(array, index);
}
}
internal class StringSet : ObjectSet { }
internal class CaseInsensitiveStringSet : StringSet {
protected override Dictionary CreateDictionary() {
return new Dictionary(StartingCapacity, StringComparer.InvariantCultureIgnoreCase);
}
}
internal class VirtualPathSet : ObjectSet { }
internal class AssemblySet : ObjectSet {
internal static AssemblySet Create(ICollection c) {
AssemblySet objectSet = new AssemblySet();
objectSet.AddCollection(c);
return objectSet;
}
}
internal class BuildProviderSet : ObjectSet { }
internal class ControlSet : ObjectSet { }
#else
/*
* Holds a set of unique objects
*/
internal class ObjectSet: ICollection {
private class EmptyEnumerator: IEnumerator {
public object Current { get { return null; } }
public bool MoveNext() { return false; }
public void Reset() {}
}
private static EmptyEnumerator _emptyEnumerator = new EmptyEnumerator();
private IDictionary _objects;
internal ObjectSet() {}
// By default, it's case sensitive
protected virtual bool CaseInsensitive { get { return false; } }
public void Add(object o) {
if (_objects == null)
_objects = new System.Collections.Specialized.HybridDictionary(CaseInsensitive);
_objects[o] = null;
}
public void AddCollection(ICollection c) {
foreach (object o in c) {
Add(o);
}
}
public void Remove(object o) {
if (_objects == null)
return;
_objects.Remove(o);
}
public bool Contains(object o) {
if (_objects == null)
return false;
return _objects.Contains(o);
}
IEnumerator IEnumerable.GetEnumerator() {
if (_objects == null)
return _emptyEnumerator;
return _objects.Keys.GetEnumerator();
}
public int Count {
get {
if (_objects == null)
return 0;
return _objects.Keys.Count;
}
}
bool ICollection.IsSynchronized {
get {
if (_objects == null)
return true;
return _objects.Keys.IsSynchronized;
}
}
object ICollection.SyncRoot {
get {
if (_objects == null)
return this;
return _objects.Keys.SyncRoot;
}
}
public void CopyTo(Array array, int index) {
if (_objects != null)
_objects.Keys.CopyTo(array, index);
}
}
internal class StringSet: ObjectSet {
internal StringSet() {}
}
internal class CaseInsensitiveStringSet: StringSet {
protected override bool CaseInsensitive { get { return true; } }
}
internal class VirtualPathSet : ObjectSet {
internal VirtualPathSet() { }
}
internal class AssemblySet : ObjectSet {
internal AssemblySet() { }
internal static AssemblySet Create(ICollection c) {
AssemblySet objectSet = new AssemblySet();
objectSet.AddCollection(c);
return objectSet;
}
}
internal class BuildProviderSet : ObjectSet {
internal BuildProviderSet() { }
}
internal class ControlSet : ObjectSet {
internal ControlSet() { }
}
#endif
}
// 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
- ThreadLocal.cs
- WasAdminWrapper.cs
- ObjectReaderCompiler.cs
- TraceSection.cs
- WeakRefEnumerator.cs
- RadioButton.cs
- ToolStripOverflowButton.cs
- RowTypeElement.cs
- Int32AnimationUsingKeyFrames.cs
- VariantWrapper.cs
- TextRangeEditTables.cs
- XmlCharacterData.cs
- DataServiceQueryException.cs
- UnmanagedMarshal.cs
- ToolStripManager.cs
- MenuScrollingVisibilityConverter.cs
- coordinatorscratchpad.cs
- KeyboardEventArgs.cs
- BindableAttribute.cs
- log.cs
- PackWebResponse.cs
- DocumentCollection.cs
- DataGridViewTextBoxColumn.cs
- StackOverflowException.cs
- OleDbErrorCollection.cs
- GridViewUpdatedEventArgs.cs
- XmlArrayAttribute.cs
- GlyphCache.cs
- BaseTemplatedMobileComponentEditor.cs
- DefaultValueTypeConverter.cs
- PriorityBindingExpression.cs
- DataTransferEventArgs.cs
- cookie.cs
- ForeignKeyConstraint.cs
- Int32CollectionValueSerializer.cs
- TextServicesPropertyRanges.cs
- MetafileHeader.cs
- GorillaCodec.cs
- SqlDataSourceSelectingEventArgs.cs
- PolicyReader.cs
- SafeNativeMethodsMilCoreApi.cs
- PlanCompiler.cs
- SyndicationDeserializer.cs
- XmlWrappingReader.cs
- StateMachine.cs
- Pts.cs
- _UriSyntax.cs
- BufferAllocator.cs
- PageCodeDomTreeGenerator.cs
- bidPrivateBase.cs
- WebReferenceOptions.cs
- ActivityDesignerLayoutSerializers.cs
- StringKeyFrameCollection.cs
- CollectionType.cs
- Unit.cs
- JournalNavigationScope.cs
- SystemDiagnosticsSection.cs
- TextFindEngine.cs
- ListSourceHelper.cs
- TextFormatterContext.cs
- DragStartedEventArgs.cs
- MouseGestureValueSerializer.cs
- TypefaceCollection.cs
- DynamicValidator.cs
- FormViewDeletedEventArgs.cs
- CompressionTracing.cs
- PeerMessageDispatcher.cs
- RoutedEventValueSerializer.cs
- Point.cs
- BitStack.cs
- FtpWebResponse.cs
- XmlSchemaSimpleTypeUnion.cs
- HwndProxyElementProvider.cs
- ResourceReferenceExpressionConverter.cs
- ViewCellRelation.cs
- RadioButtonList.cs
- safex509handles.cs
- DeclarativeCatalogPart.cs
- StylusOverProperty.cs
- _FtpControlStream.cs
- WindowsPrincipal.cs
- Menu.cs
- Throw.cs
- ViewStateModeByIdAttribute.cs
- MetadataSerializer.cs
- RoleServiceManager.cs
- Literal.cs
- XamlPathDataSerializer.cs
- ProbeDuplex11AsyncResult.cs
- SettingsSection.cs
- TreeViewImageGenerator.cs
- MarshalByRefObject.cs
- documentsequencetextpointer.cs
- SecureStringHasher.cs
- ImplicitInputBrush.cs
- EventWaitHandleSecurity.cs
- ReflectionHelper.cs
- InputScopeManager.cs
- SvcMapFileSerializer.cs
- StringFunctions.cs