本文整理汇总了C#中ICollection.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.GetType方法的具体用法?C# ICollection.GetType怎么用?C# ICollection.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: EnsureCollectionIsWritable
private void EnsureCollectionIsWritable(ICollection<object> collection)
{
bool isReadOnly = true;
try
{
if (collection != null)
{
isReadOnly = collection.IsReadOnly;
}
}
catch (Exception exception)
{
throw new ComposablePartException(
CompositionErrorId.ReflectionModel_ImportCollectionIsReadOnlyThrewException,
String.Format(CultureInfo.CurrentCulture,
Strings.ReflectionModel_ImportCollectionIsReadOnlyThrewException,
this._member.GetDisplayName(),
collection.GetType().FullName),
this.Definition.ToElement(),
exception);
}
if (isReadOnly)
{
throw new ComposablePartException(
CompositionErrorId.ReflectionModel_ImportCollectionNotWritable,
String.Format(CultureInfo.CurrentCulture,
Strings.ReflectionModel_ImportCollectionNotWritable,
this._member.GetDisplayName()),
this.Definition.ToElement());
}
}
示例3: Clear
public static void Clear(ICollection c)
{
try
{
MethodInfo method = c.GetType().GetMethod("Clear");
if (method == null)
{
method = c.GetType().GetMethod("clear");
}
method.Invoke(c, new object[0]);
}
catch (Exception e)
{
throw e;
}
}
示例4: AddRange
public override void AddRange(ICollection c)
{
if (c.GetType() != typeof(ForeignKey_1_n))
throw new CsDOException("Should add only ForeignKey");
base.AddRange(c);
}
示例5: Contains
public static bool Contains(ICollection c, object obj)
{
bool contains = false;
try
{
MethodInfo method = c.GetType().GetMethod("Contains");
if (method == null)
{
method = c.GetType().GetMethod("contains");
}
contains = (bool) method.Invoke(c, new object[] { obj });
}
catch (Exception e)
{
throw e;
}
return contains;
}
示例6: Save
public void Save(ICollection<Movie> movies)
{
if (!File.Exists(_configFile))
{
File.Create(_configFile);
}
var serializer = new XmlSerializer(movies.GetType());
var writer = new StreamWriter(_configFile);
serializer.Serialize(writer.BaseStream, movies);
writer.Close();
}
示例7: Add
public static bool Add(ICollection c, object obj)
{
bool added = false;
try
{
MethodInfo method = c.GetType().GetMethod("Add");
if (method == null)
{
method = c.GetType().GetMethod("add");
}
int index = (int) method.Invoke(c, new object[] { obj });
if (index >= 0)
{
added = true;
}
}
catch (Exception e)
{
throw e;
}
return added;
}
示例8: Add
public static bool Add(ICollection c, object obj)
{
bool flag = false;
try
{
MethodInfo method = c.GetType().GetMethod("Add");
if (method == null)
{
method = c.GetType().GetMethod("add");
}
int num = (int) method.Invoke(c, new object[] { obj });
if (num >= 0)
{
flag = true;
}
}
catch (Exception exception)
{
throw exception;
}
return flag;
}
示例9: AddAll
public static bool AddAll(ICollection target, ICollection c)
{
IEnumerator enumerator = new ArrayList(c).GetEnumerator();
bool flag = false;
try
{
MethodInfo method = target.GetType().GetMethod("addAll");
if (method != null)
{
return (bool) method.Invoke(target, new object[] { c });
}
method = target.GetType().GetMethod("Add");
while (enumerator.MoveNext())
{
bool flag2 = ((int) method.Invoke(target, new object[] { enumerator.Current })) >= 0;
flag = flag ? flag : flag2;
}
}
catch (Exception exception)
{
throw exception;
}
return flag;
}
示例10: SerialisoiXml
public static void SerialisoiXml(string tiedosto, ICollection ic)
{
XmlSerializer xs = new XmlSerializer(ic.GetType());
TextWriter tw = new StreamWriter(tiedosto);
try
{
xs.Serialize(tw, ic);
}
catch (Exception e)
{
throw e;
}
finally
{
tw.Close();
}
}
示例11: TallennaXml
public static void TallennaXml(ICollection pelaajat, string tiedosto)
{
XmlSerializer xs = new XmlSerializer(pelaajat.GetType());
TextWriter tw = new StreamWriter(tiedosto);
try
{
xs.Serialize(tw, pelaajat);
}
catch (Exception ex)
{
throw ex;
}
finally
{
tw.Close();
}
}
示例12: TestAddToCollectionTwiceAddsTwoElement
public void TestAddToCollectionTwiceAddsTwoElement(ICollection<string> collection)
{
int oldCount = collection.Count;
// Единственным предусловием метода Add является то, что текущая коллекция
// не является только для чтения! Нужно уважать свою часть контракта,
// чтобы другие вполняли свою;)
if (collection.IsReadOnly)
{
Console.WriteLine("Current list type ({0}) is readonly. Skipping it...",
collection.GetType());
return;
}
collection.Add("foo");
collection.Add("foo");
Assert.That(collection.Count, Is.GreaterThanOrEqualTo(oldCount));
Assert.IsTrue(collection.Contains("foo"));
//Assert.That(collection.Count, Is.EqualTo(oldCount + 2));
}
示例13: Compare
//
// There does not appear to be any way to compare collections
// in either C# or with the .NET framework. Something like
// C++ STL EqualRange would be nice...
//
private static bool Compare(ICollection c1, ICollection c2)
{
if (c1 == null)
{
return c2 == null;
}
if (c2 == null)
{
return false;
}
if (!c1.GetType().Equals(c2.GetType()))
{
return false;
}
if (c1.Count != c2.Count)
{
return false;
}
IEnumerator i1 = c1.GetEnumerator();
IEnumerator i2 = c2.GetEnumerator();
while (i1.MoveNext())
{
i2.MoveNext();
if (i1.Current is ICollection)
{
Debug.Assert(i2.Current is ICollection);
if (!Compare((ICollection)i1.Current, (ICollection)i2.Current))
{
return false;
}
}
else if (!i1.Current.Equals(i2.Current))
{
return false;
}
}
return true;
}
示例14: SetCollectionValues
/// <summary>
/// Sets the entries on an ICollection implementation.
/// </summary>
/// <param name="coll"></param>
/// <param name="parentNode"></param>
protected void SetCollectionValues(ICollection coll, XmlNode parentNode)
{
if (typeof(IDictionary).IsAssignableFrom(coll.GetType()))
{
// IDictionary
SetDictionaryValues((IDictionary)coll, parentNode);
return;
}
else if (typeof(IList).IsAssignableFrom(coll.GetType()))
{
// IList
SetListValues((IList)coll, parentNode);
return;
}
}
示例15: PrintCollection
static public string PrintCollection (ICollection collection)
{
StringBuilder sb = new StringBuilder ();
sb.Append (collection.GetType ());
sb.Append ("(");
bool first = true;
foreach (object o in collection) {
if (first)
first = false;
else
sb.Append (", ");
sb.Append (o);
}
sb.Append (")");
return sb.ToString ();
}