PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/tests/gtest-iter-03.cs

https://bitbucket.org/danipen/mono
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
  1. using System;
  2. using System.Collections.Generic;
  3. public class Test {
  4. List<object> annotations = new List<object> ();
  5. public IEnumerable<T> Annotations<T> () where T : class
  6. {
  7. foreach (T o in Annotations (typeof (T)))
  8. yield return o;
  9. }
  10. public IEnumerable<object> Annotations (Type type)
  11. {
  12. if (annotations == null)
  13. yield break;
  14. foreach (object o in annotations)
  15. if (o.GetType () == type)
  16. yield return o;
  17. }
  18. public static void Main ()
  19. {
  20. var test = new Test ();
  21. test.Annotations<Test> ();
  22. }
  23. }