/Mono.Cecil/ParameterDefinitionCollection.cs

http://github.com/jbevain/cecil · C# · 62 lines · 40 code · 13 blank · 9 comment · 2 complexity · 042ed63f7646a1877462807e4c5be15f MD5 · raw file

  1. //
  2. // Author:
  3. // Jb Evain (jbevain@gmail.com)
  4. //
  5. // Copyright (c) 2008 - 2015 Jb Evain
  6. // Copyright (c) 2008 - 2011 Novell, Inc.
  7. //
  8. // Licensed under the MIT/X11 license.
  9. //
  10. using System;
  11. using Mono.Collections.Generic;
  12. namespace Mono.Cecil {
  13. sealed class ParameterDefinitionCollection : Collection<ParameterDefinition> {
  14. readonly IMethodSignature method;
  15. internal ParameterDefinitionCollection (IMethodSignature method)
  16. {
  17. this.method = method;
  18. }
  19. internal ParameterDefinitionCollection (IMethodSignature method, int capacity)
  20. : base (capacity)
  21. {
  22. this.method = method;
  23. }
  24. protected override void OnAdd (ParameterDefinition item, int index)
  25. {
  26. item.method = method;
  27. item.index = index;
  28. }
  29. protected override void OnInsert (ParameterDefinition item, int index)
  30. {
  31. item.method = method;
  32. item.index = index;
  33. for (int i = index; i < size; i++)
  34. items [i].index = i + 1;
  35. }
  36. protected override void OnSet (ParameterDefinition item, int index)
  37. {
  38. item.method = method;
  39. item.index = index;
  40. }
  41. protected override void OnRemove (ParameterDefinition item, int index)
  42. {
  43. item.method = null;
  44. item.index = -1;
  45. for (int i = index + 1; i < size; i++)
  46. items [i].index = i - 1;
  47. }
  48. }
  49. }