本文整理汇总了C#中ICollection.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.GetEnumerator方法的具体用法?C# ICollection.GetEnumerator怎么用?C# ICollection.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.GetEnumerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyTo
/// <summary>
/// Copy property value of object stored in source into destination array.
/// </summary>
/// <param name="source">Source array of objects</param>
/// <param name="array">Destination array</param>
/// <param name="property">Source Object Property Name</param>
/// <param name="index">Start index in source array</param>
public static void CopyTo( ICollection source, Array array, string property, int index )
{
ArrayList list = new ArrayList( source.Count );
IEnumerator enums = source.GetEnumerator();
int iCount = 0;
PropertyInfo keyProp = null;
while( enums.MoveNext() )
{
if( keyProp == null )
{
keyProp = enums.Current.GetType().GetProperty( property );
if( keyProp == null )
throw new ArgumentException( "Property Name of object is wrong", "property" );
}
if( iCount >= index )
list.Add( keyProp.GetValue( enums.Current, null ) );
iCount++;
}
list.CopyTo( array );
list.Clear();
}
示例2: First
// List primitives
public static object First (ICollection list) {
if (list.Count < 1)
throw new ArgumentException (String.Empty, "list");
IEnumerator iterator = list.GetEnumerator ();
iterator.MoveNext ();
return iterator.Current;
}
示例3: ContainsAll
public static bool ContainsAll(ICollection target, ICollection c)
{
IEnumerator e = c.GetEnumerator();
bool contains = false;
try
{
MethodInfo method = target.GetType().GetMethod("containsAll");
if (method != null)
{
return (bool) method.Invoke(target, new object[] { c });
}
method = target.GetType().GetMethod("Contains");
while (e.MoveNext())
{
if (!(contains = (bool) method.Invoke(target, new object[] { e.Current })))
{
return contains;
}
}
}
catch (Exception ex)
{
throw ex;
}
return contains;
}
示例4: PopulateFromList
private static ICollection<object> PopulateFromList( ICollection<object> list, out ErrorRecord error )
{
ICollection<object> objs;
error = null;
List<object> objs1 = new List<object>( );
using ( IEnumerator<object> enumerator = list.GetEnumerator( ) ) {
while ( enumerator.MoveNext( ) ) {
object current = enumerator.Current;
if ( current is IDictionary<string, object> ) {
PSObject pSObject = JsonObject.PopulateFromDictionary( current as IDictionary<string, object>, out error );
if ( error == null ) {
objs1.Add( pSObject );
}
else {
objs = null;
return objs;
}
}
else if ( !( current is ICollection<object> ) ) {
objs1.Add( current );
}
else {
ICollection<object> objs2 = JsonObject.PopulateFromList( current as ICollection<object>, out error );
if ( error == null ) {
objs1.Add( objs2 );
}
else {
objs = null;
return objs;
}
}
}
return objs1.ToArray( );
}
}
示例5: ExecuteSQL
public void ExecuteSQL(ICollection<string> SQLs)
{
using (DbConnection conn = CreateDbConnection())
{
using (DbCommand command = CreateDbCommand(conn))
{
using (DbTransaction transaction = CreateTransaction(conn, command))
{
try
{
IEnumerator<string> enumerator = SQLs.GetEnumerator();
while (enumerator.MoveNext())
{
string sql = enumerator.Current;
command.CommandText = sql;
command.ExecuteNonQuery();
}
transaction.Commit();
}
catch (Exception)
{
try
{
transaction.Rollback();
}
catch (Exception)
{
throw;
}
throw;
}
} //using (DbTransaction transaction = CreateTransaction(conn, command))
} //using (DbCommand command = CreateDbCommand(conn))
} //using (DbConnection conn = CreateDbConnection())
}
示例6: Equal
public static void Equal(ICollection expected, ICollection actual)
{
Assert.Equal(expected == null, actual == null);
if (expected == null)
{
return;
}
Assert.Equal(expected.Count, actual.Count);
IEnumerator e = expected.GetEnumerator();
IEnumerator a = actual.GetEnumerator();
while (e.MoveNext())
{
Assert.True(a.MoveNext(), "actual has fewer elements");
if (e.Current == null)
{
Assert.Null(a.Current);
}
else
{
Assert.IsType(e.Current.GetType(), a.Current);
Assert.Equal(e.Current, a.Current);
}
}
Assert.False(a.MoveNext(), "actual has more elements");
}
示例7: AreCollectionsEqual
/// <summary>
/// Determines whether two collections are equal. They are equal if they contain the equal elements in the same order.
/// </summary>
/// <param name="collection1">The first collection.</param>
/// <param name="collection2">The second collection.</param>
/// <returns><c>true</c> if the collections are equal; <c>false</c> otherwise.</returns>
public static bool AreCollectionsEqual(ICollection collection1, ICollection collection2)
{
if (collection1 == null && collection2 == null)
return true;
if (collection1 == null || collection2 == null)
return false;
if (collection1.Count != collection2.Count)
return false;
IEnumerator enumerator1 = collection1.GetEnumerator ();
IEnumerator enumerator2 = collection2.GetEnumerator ();
while (true)
{
bool hasElement1 = enumerator1.MoveNext ();
bool hasElement2 = enumerator2.MoveNext ();
if (hasElement1 == false || hasElement2 == false)
break;
if (false == Comparer.Equals (enumerator1.Current, enumerator2.Current))
return false;
}
return true;
}
示例8: GetCollectionDelta
private ICollection GetCollectionDelta(ICollection original, ICollection modified)
{
if (((original != null) && (modified != null)) && (original.Count != 0))
{
IEnumerator enumerator = modified.GetEnumerator();
if (enumerator != null)
{
IDictionary dictionary = new HybridDictionary();
foreach (object obj2 in original)
{
if (dictionary.Contains(obj2))
{
int num = (int) dictionary[obj2];
dictionary[obj2] = ++num;
}
else
{
dictionary.Add(obj2, 1);
}
}
ArrayList list = null;
for (int i = 0; (i < modified.Count) && enumerator.MoveNext(); i++)
{
object current = enumerator.Current;
if (dictionary.Contains(current))
{
if (list == null)
{
list = new ArrayList();
enumerator.Reset();
for (int j = 0; (j < i) && enumerator.MoveNext(); j++)
{
list.Add(enumerator.Current);
}
enumerator.MoveNext();
}
int num4 = (int) dictionary[current];
if (--num4 == 0)
{
dictionary.Remove(current);
}
else
{
dictionary[current] = num4;
}
}
else if (list != null)
{
list.Add(current);
}
}
if (list != null)
{
return list;
}
}
}
return modified;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:59,代码来源:CollectionCodeDomSerializer.cs
示例9: Queue
// Fills a Queue with the elements of an ICollection. Uses the enumerator
// to get each of the elements.
//
public Queue(ICollection col) : this((col==null ? 32 : col.Count))
{
if (col==null)
throw new ArgumentNullException("col");
IEnumerator en = col.GetEnumerator();
while(en.MoveNext())
Enqueue(en.Current);
}
示例10: Transform
/// <summary>
/// Executes a function on each item in a <see cref="ICollection" />
/// and returns the results in a new <see cref="IList" />.
/// </summary>
/// <param name="coll"></param>
/// <param name="func"></param>
/// <returns></returns>
public static IList Transform(ICollection coll, FunctionDelegate<object> func)
{
IList result = new ArrayList();
IEnumerator i = coll.GetEnumerator();
foreach(object obj in coll)
result.Add(func(obj));
return result;
}
示例11: Stack
// Fills a Stack with the contents of a particular collection. The items are
// pushed onto the stack in the same order they are read by the enumerator.
//
public Stack(ICollection col) : this((col==null ? 32 : col.Count))
{
if (col==null)
throw new ArgumentNullException(nameof(col));
Contract.EndContractBlock();
IEnumerator en = col.GetEnumerator();
while(en.MoveNext())
Push(en.Current);
}
示例12: WriteElements
private void WriteElements(IWriteContext context, ICollection collection, ITypeHandler4
elementHandler)
{
IEnumerator elements = collection.GetEnumerator();
while (elements.MoveNext())
{
context.WriteObject(elementHandler, elements.Current);
}
}
示例13: AllElementsOfType
/// <summary>
/// Valida cada elemento de la <see cref="ICollection">ICollection</see>, lanzando una <see cref="ArgumentException">ArgumentException</see> si alguno de sus elementos no es de tipo <code>clazz</code>.
/// </summary>
/// <param name="collection">La <see cref="ICollection">ICollection</see> a validar, distinta de <code>null</code></param>
/// <param name="clazz">El tipo que se espera que sean los elementos de <code>collection</code>, distinto de <code>null</code></param>
/// <param name="message">El mensaje a mostrar en caso de que la validación falle</param>
public static void AllElementsOfType(ICollection collection, Type clazz, String message)
{
Validate.NotNull(collection);
Validate.NotNull(clazz);
for (IEnumerator it = collection.GetEnumerator(); it.MoveNext(); ) {
if (clazz.IsAssignableFrom(it.Current.GetType())) {
throw new ArgumentException(message);
}
}
}
示例14: HasElements
/// <summary>
/// Checks if the given array or collection has elements and none of the elements is null.
/// </summary>
/// <param name="collection">the collection to be checked.</param>
/// <returns>true if the collection has a length and contains only non-null elements.</returns>
public static bool HasElements(ICollection collection)
{
if (!HasLength(collection)) return false;
IEnumerator it = collection.GetEnumerator();
while(it.MoveNext())
{
if (it.Current == null ) return false;
}
return true;
}
示例15: ExtractFactory
public static IGeometryFactory ExtractFactory(ICollection<IGeometry> geoms)
{
if (geoms.Count == 0)
return null;
var geomenumerator = geoms.GetEnumerator();
geomenumerator.MoveNext();
return geomenumerator.Current.Factory;
}