/mcs/tests/gtest-iter-03.cs
C# | 28 lines | 23 code | 5 blank | 0 comment | 4 complexity | cb07c31f0ae0a9f6d28b4738025c37b2 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
- using System;
- using System.Collections.Generic;
- public class Test {
- List<object> annotations = new List<object> ();
- public IEnumerable<T> Annotations<T> () where T : class
- {
- foreach (T o in Annotations (typeof (T)))
- yield return o;
- }
- public IEnumerable<object> Annotations (Type type)
- {
- if (annotations == null)
- yield break;
- foreach (object o in annotations)
- if (o.GetType () == type)
- yield return o;
- }
-
- public static void Main ()
- {
- var test = new Test ();
- test.Annotations<Test> ();
- }
- }