Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / System / Windows / Media / Generated / Int32Collection.cs / 1 / Int32Collection.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// This file was generated, please do not edit it directly.
//
// Please see http://wiki/default.aspx/Microsoft.Projects.Avalon/MilCodeGen.html for more information.
//
//---------------------------------------------------------------------------
using MS.Internal;
using MS.Internal.KnownBoxes;
using MS.Internal.Collections;
using MS.Internal.PresentationCore;
using MS.Utility;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.ComponentModel.Design.Serialization;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;
using System.Windows.Media.Composition;
using System.Windows.Media.Imaging;
using System.Windows.Markup;
using System.Windows.Media.Converters;
using System.Security;
using System.Security.Permissions;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
// These types are aliased to match the unamanaged names used in interop
using BOOL = System.UInt32;
using WORD = System.UInt16;
using Float = System.Single;
namespace System.Windows.Media
{
///
/// A collection of ints.
///
[TypeConverter(typeof(Int32CollectionConverter))]
[ValueSerializer(typeof(Int32CollectionValueSerializer))] // Used by MarkupWriter
public sealed partial class Int32Collection : Freezable, IFormattable, IList, IList
{
//-----------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Shadows inherited Clone() with a strongly typed
/// version for convenience.
///
public new Int32Collection Clone()
{
return (Int32Collection)base.Clone();
}
///
/// Shadows inherited CloneCurrentValue() with a strongly typed
/// version for convenience.
///
public new Int32Collection CloneCurrentValue()
{
return (Int32Collection)base.CloneCurrentValue();
}
#endregion Public Methods
//------------------------------------------------------
//
// Public Properties
//
//-----------------------------------------------------
#region IList
///
/// Adds "value" to the list
///
public void Add(int value)
{
AddHelper(value);
}
///
/// Removes all elements from the list
///
public void Clear()
{
WritePreamble();
_collection.Clear();
++_version;
WritePostscript();
}
///
/// Determines if the list contains "value"
///
public bool Contains(int value)
{
ReadPreamble();
return _collection.Contains(value);
}
///
/// Returns the index of "value" in the list
///
public int IndexOf(int value)
{
ReadPreamble();
return _collection.IndexOf(value);
}
///
/// Inserts "value" into the list at the specified position
///
public void Insert(int index, int value)
{
WritePreamble();
_collection.Insert(index, value);
++_version;
WritePostscript();
}
///
/// Removes "value" from the list
///
public bool Remove(int value)
{
WritePreamble();
int index = IndexOf(value);
if (index >= 0)
{
// we already have index from IndexOf so instead of using Remove,
// which will search the collection a second time, we'll use RemoveAt
_collection.RemoveAt(index);
++_version;
WritePostscript();
return true;
}
// Collection_Remove returns true, calls WritePostscript,
// increments version, and does UpdateResource if it succeeds
return false;
}
///
/// Removes the element at the specified index
///
public void RemoveAt(int index)
{
RemoveAtWithoutFiringPublicEvents(index);
// RemoveAtWithoutFiringPublicEvents incremented the version
WritePostscript();
}
///
/// Removes the element at the specified index without firing
/// the public Changed event.
/// The caller - typically a public method - is responsible for calling
/// WritePostscript if appropriate.
///
internal void RemoveAtWithoutFiringPublicEvents(int index)
{
WritePreamble();
_collection.RemoveAt(index);
++_version;
// No WritePostScript to avoid firing the Changed event.
}
///
/// Indexer for the collection
///
public int this[int index]
{
get
{
ReadPreamble();
return _collection[index];
}
set
{
WritePreamble();
_collection[ index ] = value;
++_version;
WritePostscript();
}
}
#endregion
#region ICollection
///
/// The number of elements contained in the collection.
///
public int Count
{
get
{
ReadPreamble();
return _collection.Count;
}
}
///
/// Copies the elements of the collection into "array" starting at "index"
///
public void CopyTo(int[] array, int index)
{
ReadPreamble();
if (array == null)
{
throw new ArgumentNullException("array");
}
// This will not throw in the case that we are copying
// from an empty collection. This is consistent with the
// BCL Collection implementations. (Windows 1587365)
if (index < 0 || (index + _collection.Count) > array.Length)
{
throw new ArgumentOutOfRangeException("index");
}
_collection.CopyTo(array, index);
}
bool ICollection.IsReadOnly
{
get
{
ReadPreamble();
return IsFrozen;
}
}
#endregion
#region IEnumerable
///
/// Returns an enumerator for the collection
///
public Enumerator GetEnumerator()
{
ReadPreamble();
return new Enumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
#endregion
#region IList
bool IList.IsReadOnly
{
get
{
return ((ICollection)this).IsReadOnly;
}
}
bool IList.IsFixedSize
{
get
{
ReadPreamble();
return IsFrozen;
}
}
object IList.this[int index]
{
get
{
return this[index];
}
set
{
// Forwards to typed implementation
this[index] = Cast(value);
}
}
int IList.Add(object value)
{
// Forward to typed helper
return AddHelper(Cast(value));
}
bool IList.Contains(object value)
{
if (value is int)
{
return Contains((int)value);
}
return false;
}
int IList.IndexOf(object value)
{
if (value is int)
{
return IndexOf((int)value);
}
return -1;
}
void IList.Insert(int index, object value)
{
// Forward to IList Insert
Insert(index, Cast(value));
}
void IList.Remove(object value)
{
if (value is int)
{
Remove((int)value);
}
}
#endregion
#region ICollection
void ICollection.CopyTo(Array array, int index)
{
ReadPreamble();
if (array == null)
{
throw new ArgumentNullException("array");
}
// This will not throw in the case that we are copying
// from an empty collection. This is consistent with the
// BCL Collection implementations. (Windows 1587365)
if (index < 0 || (index + _collection.Count) > array.Length)
{
throw new ArgumentOutOfRangeException("index");
}
if (array.Rank != 1)
{
throw new ArgumentException(SR.Get(SRID.Collection_BadRank));
}
// Elsewhere in the collection we throw an AE when the type is
// bad so we do it here as well to be consistent
try
{
int count = _collection.Count;
for (int i = 0; i < count; i++)
{
array.SetValue(_collection[i], index + i);
}
}
catch (InvalidCastException e)
{
throw new ArgumentException(SR.Get(SRID.Collection_BadDestArray, this.GetType().Name), e);
}
}
bool ICollection.IsSynchronized
{
get
{
ReadPreamble();
return IsFrozen || Dispatcher != null;
}
}
object ICollection.SyncRoot
{
get
{
ReadPreamble();
return this;
}
}
#endregion
#region IEnumerable
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
#endregion
#region Internal Helpers
///
/// A frozen empty Int32Collection.
///
internal static Int32Collection Empty
{
get
{
if (s_empty == null)
{
Int32Collection collection = new Int32Collection();
collection.Freeze();
s_empty = collection;
}
return s_empty;
}
}
///
/// Helper to return read only access.
///
internal int Internal_GetItem(int i)
{
return _collection[i];
}
#endregion
#region Private Helpers
private int Cast(object value)
{
if( value == null )
{
throw new System.ArgumentNullException("value");
}
if (!(value is int))
{
throw new System.ArgumentException(SR.Get(SRID.Collection_BadType, this.GetType().Name, value.GetType().Name, "int"));
}
return (int) value;
}
// IList.Add returns int and IList.Add does not. This
// is called by both Adds and IList's just ignores the
// integer
private int AddHelper(int value)
{
int index = AddWithoutFiringPublicEvents(value);
// AddAtWithoutFiringPublicEvents incremented the version
WritePostscript();
return index;
}
internal int AddWithoutFiringPublicEvents(int value)
{
int index = -1;
WritePreamble();
index = _collection.Add(value);
++_version;
// No WritePostScript to avoid firing the Changed event.
return index;
}
#endregion Private Helpers
private static Int32Collection s_empty;
#region Public Properties
#endregion Public Properties
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
#region Protected Methods
///
/// Implementation of Freezable.CreateInstanceCore .
///
/// The new Freezable.
protected override Freezable CreateInstanceCore()
{
return new Int32Collection();
}
///
/// Implementation of Freezable.CloneCore()
///
protected override void CloneCore(Freezable source)
{
Int32Collection sourceInt32Collection = (Int32Collection) source;
base.CloneCore(source);
int count = sourceInt32Collection._collection.Count;
_collection = new FrugalStructList(count);
for (int i = 0; i < count; i++)
{
_collection.Add(sourceInt32Collection._collection[i]);
}
}
///
/// Implementation of Freezable.CloneCurrentValueCore()
///
protected override void CloneCurrentValueCore(Freezable source)
{
Int32Collection sourceInt32Collection = (Int32Collection) source;
base.CloneCurrentValueCore(source);
int count = sourceInt32Collection._collection.Count;
_collection = new FrugalStructList(count);
for (int i = 0; i < count; i++)
{
_collection.Add(sourceInt32Collection._collection[i]);
}
}
///
/// Implementation of Freezable.GetAsFrozenCore()
///
protected override void GetAsFrozenCore(Freezable source)
{
Int32Collection sourceInt32Collection = (Int32Collection) source;
base.GetAsFrozenCore(source);
int count = sourceInt32Collection._collection.Count;
_collection = new FrugalStructList(count);
for (int i = 0; i < count; i++)
{
_collection.Add(sourceInt32Collection._collection[i]);
}
}
///
/// Implementation of Freezable.GetCurrentValueAsFrozenCore()
///
protected override void GetCurrentValueAsFrozenCore(Freezable source)
{
Int32Collection sourceInt32Collection = (Int32Collection) source;
base.GetCurrentValueAsFrozenCore(source);
int count = sourceInt32Collection._collection.Count;
_collection = new FrugalStructList(count);
for (int i = 0; i < count; i++)
{
_collection.Add(sourceInt32Collection._collection[i]);
}
}
#endregion ProtectedMethods
//-----------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
#endregion Internal Methods
//-----------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
#region Internal Properties
///
/// Creates a string representation of this object based on the current culture.
///
///
/// A string representation of this object.
///
public override string ToString()
{
ReadPreamble();
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(null /* format string */, null /* format provider */);
}
///
/// Creates a string representation of this object based on the IFormatProvider
/// passed in. If the provider is null, the CurrentCulture is used.
///
///
/// A string representation of this object.
///
public string ToString(IFormatProvider provider)
{
ReadPreamble();
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(null /* format string */, provider);
}
///
/// Creates a string representation of this object based on the format string
/// and IFormatProvider passed in.
/// If the provider is null, the CurrentCulture is used.
/// See the documentation for IFormattable for more information.
///
///
/// A string representation of this object.
///
string IFormattable.ToString(string format, IFormatProvider provider)
{
ReadPreamble();
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(format, provider);
}
///
/// Creates a string representation of this object based on the format string
/// and IFormatProvider passed in.
/// If the provider is null, the CurrentCulture is used.
/// See the documentation for IFormattable for more information.
///
///
/// A string representation of this object.
///
internal string ConvertToString(string format, IFormatProvider provider)
{
if (_collection.Count == 0)
{
return String.Empty;
}
StringBuilder str = new StringBuilder();
// Consider using this separator
// Helper to get the numeric list separator for a given culture.
// char separator = MS.Internal.TokenizerHelper.GetNumericListSeparator(provider);
for (int i=0; i<_collection.Count; i++)
{
str.AppendFormat(
provider,
"{0:" + format + "}",
_collection[i]);
if (i != _collection.Count-1)
{
str.Append(" ");
}
}
return str.ToString();
}
///
/// Parse - returns an instance converted from the provided string
/// using the current culture
/// string with Int32Collection data
///
public static Int32Collection Parse(string source)
{
IFormatProvider formatProvider = CultureInfo.GetCultureInfo("en-us");
TokenizerHelper th = new TokenizerHelper(source, formatProvider);
Int32Collection resource = new Int32Collection();
int value;
while (th.NextToken())
{
value = Convert.ToInt32(th.GetCurrentToken(), formatProvider);
resource.Add(value);
}
return resource;
}
#endregion Internal Properties
//-----------------------------------------------------
//
// Dependency Properties
//
//------------------------------------------------------
#region Dependency Properties
#endregion Dependency Properties
//-----------------------------------------------------
//
// Internal Fields
//
//------------------------------------------------------
#region Internal Fields
internal FrugalStructList _collection;
internal uint _version = 0;
#endregion Internal Fields
#region Enumerator
///
/// Enumerates the items in a intCollection
///
public struct Enumerator : IEnumerator, IEnumerator
{
#region Constructor
internal Enumerator(Int32Collection list)
{
Debug.Assert(list != null, "list may not be null.");
_list = list;
_version = list._version;
_index = -1;
_current = default(int);
}
#endregion
#region Methods
void IDisposable.Dispose()
{
}
///
/// Advances the enumerator to the next element of the collection.
///
///
/// true if the enumerator was successfully advanced to the next element,
/// false if the enumerator has passed the end of the collection.
///
public bool MoveNext()
{
_list.ReadPreamble();
if (_version == _list._version)
{
if (_index > -2 && _index < _list._collection.Count - 1)
{
_current = _list._collection[++_index];
return true;
}
else
{
_index = -2; // -2 indicates "past the end"
return false;
}
}
else
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
}
}
///
/// Sets the enumerator to its initial position, which is before the
/// first element in the collection.
///
public void Reset()
{
_list.ReadPreamble();
if (_version == _list._version)
{
_index = -1;
}
else
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
}
}
#endregion
#region Properties
object IEnumerator.Current
{
get
{
return this.Current;
}
}
///
/// Current element
///
/// The behavior of IEnumerable<T>.Current is undefined
/// before the first MoveNext and after we have walked
/// off the end of the list. However, the IEnumerable.Current
/// contract requires that we throw exceptions
///
public int Current
{
get
{
if (_index > -1)
{
return _current;
}
else if (_index == -1)
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_NotStarted));
}
else
{
Debug.Assert(_index == -2, "expected -2, got " + _index + "\n");
throw new InvalidOperationException(SR.Get(SRID.Enumerator_ReachedEnd));
}
}
}
#endregion
#region Data
private int _current;
private Int32Collection _list;
private uint _version;
private int _index;
#endregion
}
#endregion
#region Constructors
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Initializes a new instance that is empty.
///
public Int32Collection()
{
_collection = new FrugalStructList();
}
///
/// Initializes a new instance that is empty and has the specified initial capacity.
///
/// int - The number of elements that the new list is initially capable of storing.
public Int32Collection(int capacity)
{
_collection = new FrugalStructList(capacity);
}
///
/// Creates a Int32Collection with all of the same elements as collection
///
public Int32Collection(IEnumerable collection)
{
// The WritePreamble and WritePostscript aren't technically necessary
// in the constructor as of 1/20/05 but they are put here in case
// their behavior changes at a later date
WritePreamble();
if (collection != null)
{
ICollection icollectionOfT = collection as ICollection;
if (icollectionOfT != null)
{
_collection = new FrugalStructList(icollectionOfT);
}
else
{
ICollection icollection = collection as ICollection;
if (icollection != null) // an IC but not and IC
{
_collection = new FrugalStructList(icollection);
}
else // not a IC or IC so fall back to the slower Add
{
_collection = new FrugalStructList();
foreach (int item in collection)
{
_collection.Add(item);
}
}
}
WritePostscript();
}
else
{
throw new ArgumentNullException("collection");
}
}
#endregion Constructors
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// This file was generated, please do not edit it directly.
//
// Please see http://wiki/default.aspx/Microsoft.Projects.Avalon/MilCodeGen.html for more information.
//
//---------------------------------------------------------------------------
using MS.Internal;
using MS.Internal.KnownBoxes;
using MS.Internal.Collections;
using MS.Internal.PresentationCore;
using MS.Utility;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.ComponentModel.Design.Serialization;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;
using System.Windows.Media.Composition;
using System.Windows.Media.Imaging;
using System.Windows.Markup;
using System.Windows.Media.Converters;
using System.Security;
using System.Security.Permissions;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
// These types are aliased to match the unamanaged names used in interop
using BOOL = System.UInt32;
using WORD = System.UInt16;
using Float = System.Single;
namespace System.Windows.Media
{
///
/// A collection of ints.
///
[TypeConverter(typeof(Int32CollectionConverter))]
[ValueSerializer(typeof(Int32CollectionValueSerializer))] // Used by MarkupWriter
public sealed partial class Int32Collection : Freezable, IFormattable, IList, IList
{
//-----------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
#region Public Methods
///
/// Shadows inherited Clone() with a strongly typed
/// version for convenience.
///
public new Int32Collection Clone()
{
return (Int32Collection)base.Clone();
}
///
/// Shadows inherited CloneCurrentValue() with a strongly typed
/// version for convenience.
///
public new Int32Collection CloneCurrentValue()
{
return (Int32Collection)base.CloneCurrentValue();
}
#endregion Public Methods
//------------------------------------------------------
//
// Public Properties
//
//-----------------------------------------------------
#region IList
///
/// Adds "value" to the list
///
public void Add(int value)
{
AddHelper(value);
}
///
/// Removes all elements from the list
///
public void Clear()
{
WritePreamble();
_collection.Clear();
++_version;
WritePostscript();
}
///
/// Determines if the list contains "value"
///
public bool Contains(int value)
{
ReadPreamble();
return _collection.Contains(value);
}
///
/// Returns the index of "value" in the list
///
public int IndexOf(int value)
{
ReadPreamble();
return _collection.IndexOf(value);
}
///
/// Inserts "value" into the list at the specified position
///
public void Insert(int index, int value)
{
WritePreamble();
_collection.Insert(index, value);
++_version;
WritePostscript();
}
///
/// Removes "value" from the list
///
public bool Remove(int value)
{
WritePreamble();
int index = IndexOf(value);
if (index >= 0)
{
// we already have index from IndexOf so instead of using Remove,
// which will search the collection a second time, we'll use RemoveAt
_collection.RemoveAt(index);
++_version;
WritePostscript();
return true;
}
// Collection_Remove returns true, calls WritePostscript,
// increments version, and does UpdateResource if it succeeds
return false;
}
///
/// Removes the element at the specified index
///
public void RemoveAt(int index)
{
RemoveAtWithoutFiringPublicEvents(index);
// RemoveAtWithoutFiringPublicEvents incremented the version
WritePostscript();
}
///
/// Removes the element at the specified index without firing
/// the public Changed event.
/// The caller - typically a public method - is responsible for calling
/// WritePostscript if appropriate.
///
internal void RemoveAtWithoutFiringPublicEvents(int index)
{
WritePreamble();
_collection.RemoveAt(index);
++_version;
// No WritePostScript to avoid firing the Changed event.
}
///
/// Indexer for the collection
///
public int this[int index]
{
get
{
ReadPreamble();
return _collection[index];
}
set
{
WritePreamble();
_collection[ index ] = value;
++_version;
WritePostscript();
}
}
#endregion
#region ICollection
///
/// The number of elements contained in the collection.
///
public int Count
{
get
{
ReadPreamble();
return _collection.Count;
}
}
///
/// Copies the elements of the collection into "array" starting at "index"
///
public void CopyTo(int[] array, int index)
{
ReadPreamble();
if (array == null)
{
throw new ArgumentNullException("array");
}
// This will not throw in the case that we are copying
// from an empty collection. This is consistent with the
// BCL Collection implementations. (Windows 1587365)
if (index < 0 || (index + _collection.Count) > array.Length)
{
throw new ArgumentOutOfRangeException("index");
}
_collection.CopyTo(array, index);
}
bool ICollection.IsReadOnly
{
get
{
ReadPreamble();
return IsFrozen;
}
}
#endregion
#region IEnumerable
///
/// Returns an enumerator for the collection
///
public Enumerator GetEnumerator()
{
ReadPreamble();
return new Enumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
#endregion
#region IList
bool IList.IsReadOnly
{
get
{
return ((ICollection)this).IsReadOnly;
}
}
bool IList.IsFixedSize
{
get
{
ReadPreamble();
return IsFrozen;
}
}
object IList.this[int index]
{
get
{
return this[index];
}
set
{
// Forwards to typed implementation
this[index] = Cast(value);
}
}
int IList.Add(object value)
{
// Forward to typed helper
return AddHelper(Cast(value));
}
bool IList.Contains(object value)
{
if (value is int)
{
return Contains((int)value);
}
return false;
}
int IList.IndexOf(object value)
{
if (value is int)
{
return IndexOf((int)value);
}
return -1;
}
void IList.Insert(int index, object value)
{
// Forward to IList Insert
Insert(index, Cast(value));
}
void IList.Remove(object value)
{
if (value is int)
{
Remove((int)value);
}
}
#endregion
#region ICollection
void ICollection.CopyTo(Array array, int index)
{
ReadPreamble();
if (array == null)
{
throw new ArgumentNullException("array");
}
// This will not throw in the case that we are copying
// from an empty collection. This is consistent with the
// BCL Collection implementations. (Windows 1587365)
if (index < 0 || (index + _collection.Count) > array.Length)
{
throw new ArgumentOutOfRangeException("index");
}
if (array.Rank != 1)
{
throw new ArgumentException(SR.Get(SRID.Collection_BadRank));
}
// Elsewhere in the collection we throw an AE when the type is
// bad so we do it here as well to be consistent
try
{
int count = _collection.Count;
for (int i = 0; i < count; i++)
{
array.SetValue(_collection[i], index + i);
}
}
catch (InvalidCastException e)
{
throw new ArgumentException(SR.Get(SRID.Collection_BadDestArray, this.GetType().Name), e);
}
}
bool ICollection.IsSynchronized
{
get
{
ReadPreamble();
return IsFrozen || Dispatcher != null;
}
}
object ICollection.SyncRoot
{
get
{
ReadPreamble();
return this;
}
}
#endregion
#region IEnumerable
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
#endregion
#region Internal Helpers
///
/// A frozen empty Int32Collection.
///
internal static Int32Collection Empty
{
get
{
if (s_empty == null)
{
Int32Collection collection = new Int32Collection();
collection.Freeze();
s_empty = collection;
}
return s_empty;
}
}
///
/// Helper to return read only access.
///
internal int Internal_GetItem(int i)
{
return _collection[i];
}
#endregion
#region Private Helpers
private int Cast(object value)
{
if( value == null )
{
throw new System.ArgumentNullException("value");
}
if (!(value is int))
{
throw new System.ArgumentException(SR.Get(SRID.Collection_BadType, this.GetType().Name, value.GetType().Name, "int"));
}
return (int) value;
}
// IList.Add returns int and IList.Add does not. This
// is called by both Adds and IList's just ignores the
// integer
private int AddHelper(int value)
{
int index = AddWithoutFiringPublicEvents(value);
// AddAtWithoutFiringPublicEvents incremented the version
WritePostscript();
return index;
}
internal int AddWithoutFiringPublicEvents(int value)
{
int index = -1;
WritePreamble();
index = _collection.Add(value);
++_version;
// No WritePostScript to avoid firing the Changed event.
return index;
}
#endregion Private Helpers
private static Int32Collection s_empty;
#region Public Properties
#endregion Public Properties
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
#region Protected Methods
///
/// Implementation of Freezable.CreateInstanceCore .
///
/// The new Freezable.
protected override Freezable CreateInstanceCore()
{
return new Int32Collection();
}
///
/// Implementation of Freezable.CloneCore()
///
protected override void CloneCore(Freezable source)
{
Int32Collection sourceInt32Collection = (Int32Collection) source;
base.CloneCore(source);
int count = sourceInt32Collection._collection.Count;
_collection = new FrugalStructList(count);
for (int i = 0; i < count; i++)
{
_collection.Add(sourceInt32Collection._collection[i]);
}
}
///
/// Implementation of Freezable.CloneCurrentValueCore()
///
protected override void CloneCurrentValueCore(Freezable source)
{
Int32Collection sourceInt32Collection = (Int32Collection) source;
base.CloneCurrentValueCore(source);
int count = sourceInt32Collection._collection.Count;
_collection = new FrugalStructList(count);
for (int i = 0; i < count; i++)
{
_collection.Add(sourceInt32Collection._collection[i]);
}
}
///
/// Implementation of Freezable.GetAsFrozenCore()
///
protected override void GetAsFrozenCore(Freezable source)
{
Int32Collection sourceInt32Collection = (Int32Collection) source;
base.GetAsFrozenCore(source);
int count = sourceInt32Collection._collection.Count;
_collection = new FrugalStructList(count);
for (int i = 0; i < count; i++)
{
_collection.Add(sourceInt32Collection._collection[i]);
}
}
///
/// Implementation of Freezable.GetCurrentValueAsFrozenCore()
///
protected override void GetCurrentValueAsFrozenCore(Freezable source)
{
Int32Collection sourceInt32Collection = (Int32Collection) source;
base.GetCurrentValueAsFrozenCore(source);
int count = sourceInt32Collection._collection.Count;
_collection = new FrugalStructList(count);
for (int i = 0; i < count; i++)
{
_collection.Add(sourceInt32Collection._collection[i]);
}
}
#endregion ProtectedMethods
//-----------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
#endregion Internal Methods
//-----------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
#region Internal Properties
///
/// Creates a string representation of this object based on the current culture.
///
///
/// A string representation of this object.
///
public override string ToString()
{
ReadPreamble();
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(null /* format string */, null /* format provider */);
}
///
/// Creates a string representation of this object based on the IFormatProvider
/// passed in. If the provider is null, the CurrentCulture is used.
///
///
/// A string representation of this object.
///
public string ToString(IFormatProvider provider)
{
ReadPreamble();
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(null /* format string */, provider);
}
///
/// Creates a string representation of this object based on the format string
/// and IFormatProvider passed in.
/// If the provider is null, the CurrentCulture is used.
/// See the documentation for IFormattable for more information.
///
///
/// A string representation of this object.
///
string IFormattable.ToString(string format, IFormatProvider provider)
{
ReadPreamble();
// Delegate to the internal method which implements all ToString calls.
return ConvertToString(format, provider);
}
///
/// Creates a string representation of this object based on the format string
/// and IFormatProvider passed in.
/// If the provider is null, the CurrentCulture is used.
/// See the documentation for IFormattable for more information.
///
///
/// A string representation of this object.
///
internal string ConvertToString(string format, IFormatProvider provider)
{
if (_collection.Count == 0)
{
return String.Empty;
}
StringBuilder str = new StringBuilder();
// Consider using this separator
// Helper to get the numeric list separator for a given culture.
// char separator = MS.Internal.TokenizerHelper.GetNumericListSeparator(provider);
for (int i=0; i<_collection.Count; i++)
{
str.AppendFormat(
provider,
"{0:" + format + "}",
_collection[i]);
if (i != _collection.Count-1)
{
str.Append(" ");
}
}
return str.ToString();
}
///
/// Parse - returns an instance converted from the provided string
/// using the current culture
/// string with Int32Collection data
///
public static Int32Collection Parse(string source)
{
IFormatProvider formatProvider = CultureInfo.GetCultureInfo("en-us");
TokenizerHelper th = new TokenizerHelper(source, formatProvider);
Int32Collection resource = new Int32Collection();
int value;
while (th.NextToken())
{
value = Convert.ToInt32(th.GetCurrentToken(), formatProvider);
resource.Add(value);
}
return resource;
}
#endregion Internal Properties
//-----------------------------------------------------
//
// Dependency Properties
//
//------------------------------------------------------
#region Dependency Properties
#endregion Dependency Properties
//-----------------------------------------------------
//
// Internal Fields
//
//------------------------------------------------------
#region Internal Fields
internal FrugalStructList _collection;
internal uint _version = 0;
#endregion Internal Fields
#region Enumerator
///
/// Enumerates the items in a intCollection
///
public struct Enumerator : IEnumerator, IEnumerator
{
#region Constructor
internal Enumerator(Int32Collection list)
{
Debug.Assert(list != null, "list may not be null.");
_list = list;
_version = list._version;
_index = -1;
_current = default(int);
}
#endregion
#region Methods
void IDisposable.Dispose()
{
}
///
/// Advances the enumerator to the next element of the collection.
///
///
/// true if the enumerator was successfully advanced to the next element,
/// false if the enumerator has passed the end of the collection.
///
public bool MoveNext()
{
_list.ReadPreamble();
if (_version == _list._version)
{
if (_index > -2 && _index < _list._collection.Count - 1)
{
_current = _list._collection[++_index];
return true;
}
else
{
_index = -2; // -2 indicates "past the end"
return false;
}
}
else
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
}
}
///
/// Sets the enumerator to its initial position, which is before the
/// first element in the collection.
///
public void Reset()
{
_list.ReadPreamble();
if (_version == _list._version)
{
_index = -1;
}
else
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
}
}
#endregion
#region Properties
object IEnumerator.Current
{
get
{
return this.Current;
}
}
///
/// Current element
///
/// The behavior of IEnumerable<T>.Current is undefined
/// before the first MoveNext and after we have walked
/// off the end of the list. However, the IEnumerable.Current
/// contract requires that we throw exceptions
///
public int Current
{
get
{
if (_index > -1)
{
return _current;
}
else if (_index == -1)
{
throw new InvalidOperationException(SR.Get(SRID.Enumerator_NotStarted));
}
else
{
Debug.Assert(_index == -2, "expected -2, got " + _index + "\n");
throw new InvalidOperationException(SR.Get(SRID.Enumerator_ReachedEnd));
}
}
}
#endregion
#region Data
private int _current;
private Int32Collection _list;
private uint _version;
private int _index;
#endregion
}
#endregion
#region Constructors
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Initializes a new instance that is empty.
///
public Int32Collection()
{
_collection = new FrugalStructList();
}
///
/// Initializes a new instance that is empty and has the specified initial capacity.
///
/// int - The number of elements that the new list is initially capable of storing.
public Int32Collection(int capacity)
{
_collection = new FrugalStructList(capacity);
}
///
/// Creates a Int32Collection with all of the same elements as collection
///
public Int32Collection(IEnumerable collection)
{
// The WritePreamble and WritePostscript aren't technically necessary
// in the constructor as of 1/20/05 but they are put here in case
// their behavior changes at a later date
WritePreamble();
if (collection != null)
{
ICollection icollectionOfT = collection as ICollection;
if (icollectionOfT != null)
{
_collection = new FrugalStructList(icollectionOfT);
}
else
{
ICollection icollection = collection as ICollection;
if (icollection != null) // an IC but not and IC
{
_collection = new FrugalStructList(icollection);
}
else // not a IC or IC so fall back to the slower Add
{
_collection = new FrugalStructList();
foreach (int item in collection)
{
_collection.Add(item);
}
}
}
WritePostscript();
}
else
{
throw new ArgumentNullException("collection");
}
}
#endregion Constructors
}
}
// 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
- GridPatternIdentifiers.cs
- DoubleCollectionValueSerializer.cs
- AutomationEvent.cs
- TypeUtil.cs
- MimeMapping.cs
- SQLDoubleStorage.cs
- OutputCacheModule.cs
- SerializerDescriptor.cs
- MaterialGroup.cs
- XmlSiteMapProvider.cs
- UriScheme.cs
- ItemList.cs
- ListViewGroup.cs
- CompilerGeneratedAttribute.cs
- DetailsViewDeleteEventArgs.cs
- ToolStripComboBox.cs
- ISessionStateStore.cs
- CheckoutException.cs
- AsymmetricKeyExchangeDeformatter.cs
- HTMLTagNameToTypeMapper.cs
- Positioning.cs
- Int64AnimationUsingKeyFrames.cs
- Base64Decoder.cs
- ParagraphResult.cs
- CollectionBuilder.cs
- ValidationSummary.cs
- KeyTime.cs
- SQLCharsStorage.cs
- TextPattern.cs
- AnyReturnReader.cs
- TextFormattingConverter.cs
- ToolStripOverflowButton.cs
- arc.cs
- SignatureToken.cs
- TypeToken.cs
- OracleLob.cs
- CatalogPartCollection.cs
- DoubleLink.cs
- DataSetUtil.cs
- BaseServiceProvider.cs
- NominalTypeEliminator.cs
- FileDialogCustomPlace.cs
- GetBrowserTokenRequest.cs
- CapacityStreamGeometryContext.cs
- GridView.cs
- LocatorGroup.cs
- SqlBulkCopyColumnMapping.cs
- GridEntry.cs
- OptionUsage.cs
- HttpRuntime.cs
- RegisteredArrayDeclaration.cs
- SamlAuthorizationDecisionStatement.cs
- ChtmlImageAdapter.cs
- SourceElementsCollection.cs
- WebPartHeaderCloseVerb.cs
- ListViewDataItem.cs
- KnownTypeDataContractResolver.cs
- FtpWebRequest.cs
- BitStream.cs
- ColorConverter.cs
- Preprocessor.cs
- ControlBuilder.cs
- ObjectStateManagerMetadata.cs
- AsymmetricSignatureDeformatter.cs
- SslStream.cs
- CultureMapper.cs
- Speller.cs
- TextRangeEdit.cs
- SplitContainerDesigner.cs
- DataGridToolTip.cs
- AppDomain.cs
- CacheMemory.cs
- TiffBitmapDecoder.cs
- TemplateBindingExpressionConverter.cs
- InputBuffer.cs
- AuthorizationRule.cs
- TextOptionsInternal.cs
- StrokeCollection.cs
- MenuItem.cs
- QueryContinueDragEventArgs.cs
- PositiveTimeSpanValidatorAttribute.cs
- TickBar.cs
- Point3D.cs
- URLIdentityPermission.cs
- ReadOnlyTernaryTree.cs
- MenuItemStyle.cs
- Wildcard.cs
- AdornerLayer.cs
- Bitmap.cs
- ComboBoxItem.cs
- TableParagraph.cs
- SqlDependency.cs
- XmlKeywords.cs
- CodeTypeDeclaration.cs
- RadialGradientBrush.cs
- ColorContext.cs
- ToolStrip.cs
- RIPEMD160Managed.cs
- PublisherMembershipCondition.cs
- EntitySqlException.cs