ProtoEnumAttribute.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. namespace ProtoBuf
  3. {
  4. /// <summary>
  5. /// Used to define protocol-buffer specific behavior for
  6. /// enumerated values.
  7. /// </summary>
  8. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
  9. public sealed class ProtoEnumAttribute : Attribute
  10. {
  11. /// <summary>
  12. /// Gets or sets the specific value to use for this enum during serialization.
  13. /// </summary>
  14. public int Value
  15. {
  16. get { return enumValue; }
  17. set { this.enumValue = value; hasValue = true; }
  18. }
  19. /// <summary>
  20. /// Indicates whether this instance has a customised value mapping
  21. /// </summary>
  22. /// <returns>true if a specific value is set</returns>
  23. public bool HasValue() { return hasValue; }
  24. private bool hasValue;
  25. private int enumValue;
  26. /// <summary>
  27. /// Gets or sets the defined name of the enum, as used in .proto
  28. /// (this name is not used during serialization).
  29. /// </summary>
  30. public string Name { get { return name; } set { name = value; } }
  31. private string name;
  32. }
  33. }