EnumerableFormatAttribute.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Edge.Core.Parser.BinaryParser.Attributes
  7. {
  8. /// <summary>
  9. /// only for ListT structure, not for primitive array.
  10. /// </summary>
  11. [AttributeUsage(AttributeTargets.Property)]
  12. public class EnumerableFormatAttribute : AttributeBase
  13. {
  14. private EnumerableFormatAttribute()
  15. {
  16. // default set to 1 since the most possible used primitive type is byte.
  17. this.ElementLength = 1;
  18. }
  19. /// <summary>
  20. ///
  21. /// </summary>
  22. /// <param name="fixedCount">The current Enumerable field has a constant count. like 2,3</param>
  23. /// <param name="index"></param>
  24. public EnumerableFormatAttribute(int fixedCount, int index)
  25. : this()
  26. {
  27. base.FixedLengthOrCount = fixedCount;
  28. base.Index = index;
  29. }
  30. /// <summary>
  31. ///
  32. /// </summary>
  33. /// <param name="countLink">the current Enumerable field is variable count and determined by another field's numerical value, and the
  34. /// numerical value directly reflect the original field count, like field 'IamTheCountLink' has the value 8, then the
  35. /// linking field count is 8.</param>
  36. /// <param name="index"></param>
  37. public EnumerableFormatAttribute(string countLink, int index)
  38. : this()
  39. {
  40. base.LengthOrCountLink = countLink;
  41. base.Index = index;
  42. }
  43. /// <summary>
  44. ///
  45. /// </summary>
  46. /// <param name="countLink">the current Enumerable field is variable count and determined by another field with numerical value, and the
  47. /// numerical value is NOT directly reflect the original field length, have to use the argument 'countLinkExpression' together
  48. /// to detect the length, like field 'IamTheCountLink' has the value 8, and the 'countLinkExpression' contains "8:12;", then the
  49. /// original field count is actually 12.</param>
  50. /// <param name="countLinkExpression"></param>
  51. /// <param name="index"></param>
  52. public EnumerableFormatAttribute(string countLink, string countLinkExpression, int index)
  53. : this()
  54. {
  55. base.LengthOrCountLink = countLink;
  56. base.LengthOrCountLinkExpression = countLinkExpression;
  57. base.Index = index;
  58. }
  59. /// <summary>
  60. /// If a fixed length field, then set the length value. otherwise, leave it.
  61. /// </summary>
  62. public int ElementLength { get; private set; }
  63. }
  64. }