当前位置: 首页>>代码示例>>C#>>正文


C# ICollection.GetType方法代码示例

本文整理汇总了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;
 }
开发者ID:psrodriguez,项目名称:CIAPI.CS,代码行数:26,代码来源:CollectionsSupport.cs

示例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());
            }
        }
开发者ID:grothag,项目名称:pocketmef,代码行数:33,代码来源:ImportingMember.cs

示例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;
     }
 }
开发者ID:psrodriguez,项目名称:CIAPI.CS,代码行数:16,代码来源:CollectionsSupport.cs

示例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);
        }
开发者ID:MonoBrasil,项目名称:historico,代码行数:7,代码来源:CsDO.ForeignKey.cs

示例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;
 }
开发者ID:psrodriguez,项目名称:CIAPI.CS,代码行数:18,代码来源:CollectionsSupport.cs

示例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();
        }
开发者ID:hegaojie,项目名称:MovieHouse,代码行数:12,代码来源:MovieConfig.cs

示例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;
 }
开发者ID:psrodriguez,项目名称:CIAPI.CS,代码行数:22,代码来源:CollectionsSupport.cs

示例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;
 }
开发者ID:89sos98,项目名称:TradingApi.Client.CS,代码行数:22,代码来源:CollectionsSupport.cs

示例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;
 }
开发者ID:89sos98,项目名称:TradingApi.Client.CS,代码行数:24,代码来源:CollectionsSupport.cs

示例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();
   }
 }
开发者ID:MikPak,项目名称:IIO11300,代码行数:17,代码来源:BLSerialisoija.cs

示例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();
            }
        }
开发者ID:TeemuTT,项目名称:IIO11300,代码行数:18,代码来源:BLSerializer.cs

示例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));
        }
开发者ID:SergeyTeplyakov,项目名称:ContractsAndInheritance,代码行数:20,代码来源:DoubleElementCollectionTests.cs

示例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;
    }
开发者ID:Crysty-Yui,项目名称:ice,代码行数:45,代码来源:AllTests.cs

示例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;
     }
 }
开发者ID:hpbaotho,项目名称:sambapos,代码行数:20,代码来源:XmlDeserializerHelper.cs

示例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 ();
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:19,代码来源:report.cs


注:本文中的ICollection.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。