Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SerieComponentAttribute.cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// The attribute for serie component.
  7. /// |可添加到Serie的组件。
  8. /// </summary>
  9. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  10. public sealed class SerieComponentAttribute : Attribute
  11. {
  12. public readonly List<Type> types = new List<Type>();
  13. public SerieComponentAttribute()
  14. { }
  15. public SerieComponentAttribute(Type type1)
  16. {
  17. AddType(type1);
  18. }
  19. public SerieComponentAttribute(Type type1, Type type2)
  20. {
  21. AddType(type1);
  22. AddType(type2);
  23. }
  24. public SerieComponentAttribute(Type type1, Type type2, Type type3)
  25. {
  26. AddType(type1);
  27. AddType(type2);
  28. AddType(type3);
  29. }
  30. public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4)
  31. {
  32. AddType(type1);
  33. AddType(type2);
  34. AddType(type3);
  35. AddType(type4);
  36. }
  37. public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5)
  38. {
  39. AddType(type1);
  40. AddType(type2);
  41. AddType(type3);
  42. AddType(type4);
  43. AddType(type5);
  44. }
  45. public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6)
  46. {
  47. AddType(type1);
  48. AddType(type2);
  49. AddType(type3);
  50. AddType(type4);
  51. AddType(type5);
  52. AddType(type6);
  53. }
  54. public SerieComponentAttribute(Type type1, Type type2, Type type3, Type type4, Type type5, Type type6, Type type7)
  55. {
  56. AddType(type1);
  57. AddType(type2);
  58. AddType(type3);
  59. AddType(type4);
  60. AddType(type5);
  61. AddType(type6);
  62. AddType(type7);
  63. }
  64. private void AddType(Type type)
  65. {
  66. if (!Serie.extraComponentMap.ContainsKey(type))
  67. throw new ArgumentException("Serie not support extra component:" + type);
  68. types.Add(type);
  69. }
  70. public bool Contains<T>() where T : ISerieComponent
  71. {
  72. return Contains(typeof(T));
  73. }
  74. public bool Contains(Type type)
  75. {
  76. return types.Contains(type);
  77. }
  78. }
  79. }