/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributes.cs

http://github.com/icsharpcode/ILSpy · C# · 84 lines · 62 code · 2 blank · 20 comment · 0 complexity · 08b71b3c39c73c616a89c02eae0e1e9a MD5 · raw file

  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. namespace aa
  20. {
  21. public static class CustomAttributes
  22. {
  23. [Flags]
  24. public enum EnumWithFlag
  25. {
  26. All = 15,
  27. None = 0,
  28. Item1 = 1,
  29. Item2 = 2,
  30. Item3 = 4,
  31. Item4 = 8
  32. }
  33. [AttributeUsage(AttributeTargets.All)]
  34. public class MyAttribute : Attribute
  35. {
  36. public MyAttribute(object val)
  37. {
  38. }
  39. }
  40. [CustomAttributes.MyAttribute(CustomAttributes.ULongEnum.MaxUInt64)]
  41. public enum ULongEnum : ulong
  42. {
  43. MaxUInt64 = 18446744073709551615uL
  44. }
  45. [CustomAttributes.MyAttribute(CustomAttributes.EnumWithFlag.Item1 | CustomAttributes.EnumWithFlag.Item2)]
  46. private static int field;
  47. [CustomAttributes.MyAttribute(CustomAttributes.EnumWithFlag.All)]
  48. public static string Property
  49. {
  50. get
  51. {
  52. return "aa";
  53. }
  54. }
  55. [Obsolete("some message")]
  56. public static void ObsoletedMethod()
  57. {
  58. //Console.WriteLine("{0} $$$ {1}", AttributeTargets.Interface, (AttributeTargets)(AttributeTargets.Property | AttributeTargets.Field));
  59. Console.WriteLine("{0} $$$ {1}", AttributeTargets.Interface, AttributeTargets.Property | AttributeTargets.Field);
  60. AttributeTargets attributeTargets = AttributeTargets.Property | AttributeTargets.Field;
  61. Console.WriteLine("{0} $$$ {1}", AttributeTargets.Interface, attributeTargets);
  62. }
  63. // No Boxing
  64. [CustomAttributes.MyAttribute(new StringComparison[]
  65. {
  66. StringComparison.Ordinal,
  67. StringComparison.CurrentCulture
  68. })]
  69. public static void ArrayAsAttribute1()
  70. {
  71. }
  72. // Boxing of each array element
  73. [CustomAttributes.MyAttribute(new object[]
  74. {
  75. StringComparison.Ordinal,
  76. StringComparison.CurrentCulture
  77. })]
  78. public static void ArrayAsAttribute2()
  79. {
  80. }
  81. }
  82. }