fork download
  1. using System;
  2.  
  3. public class CustomAttribute : Attribute
  4. {
  5. public CustomAttribute (string value)
  6. {
  7. Value = value;
  8. }
  9.  
  10. public string Value { get; private set; }
  11. }
  12.  
  13. public enum EnumType
  14. {
  15. [Custom("value1")]
  16. Value1,
  17. [Custom("value2")]
  18. Value2,
  19. [Custom("value3")]
  20. Value3
  21. }
  22.  
  23. class MainClass
  24. {
  25. static void Main(string[] args)
  26. {
  27. var memInfo = typeof(EnumType).GetMember(EnumType.Value1.ToString());
  28. Console.WriteLine("memInfo length is {0}", memInfo.Length);
  29. var attributes = memInfo[0].GetCustomAttributes(typeof(CustomAttribute), false);
  30. Console.WriteLine("attributes length is {0}", attributes.Length);
  31. }
  32. }
  33.  
Success #stdin #stdout 0.05s 34024KB
stdin
Standard input is empty
stdout
memInfo length is 1
attributes length is 1