[Wasm] Fix memory override in mono_wasm_add_assembly
[mono-project.git] / mcs / tests / test-397.cs
blob1270a51f9d9603b03a90e99427e488baffc60dc8
1 //
2 // Access modifiers
3 // We use reflection to test that the flags are the correct ones
4 //
6 using System;
7 using System.Reflection;
9 [AttributeUsage (AttributeTargets.Class)]
10 public class TypeCheckAttribute : Attribute {
12 public TypeCheckAttribute ()
17 [AttributeUsage (AttributeTargets.Property)]
18 public class PropertyCheckAttribute : Attribute {
20 public PropertyCheckAttribute ()
25 [AttributeUsage (AttributeTargets.Method)]
26 public class AccessorCheckAttribute : Attribute {
27 MethodAttributes flags;
29 public AccessorCheckAttribute (MethodAttributes flags)
31 this.flags = flags;
34 public MethodAttributes Attributes {
35 get {
36 return flags;
41 public class Test {
43 public static int Main (string [] args)
45 Type t = typeof (A);
47 foreach (PropertyInfo pi in t.GetProperties ()) {
48 object [] attrs = pi.GetCustomAttributes (typeof (PropertyCheckAttribute), true);
49 if (attrs == null)
50 return 0;
52 MethodInfo get_accessor, set_accessor;
53 get_accessor = pi.GetGetMethod (true);
54 set_accessor = pi.GetSetMethod (true);
56 if (get_accessor != null)
57 CheckFlags (pi, get_accessor);
58 if (set_accessor != null)
59 CheckFlags (pi, set_accessor);
62 return 0;
65 static void CheckFlags (PropertyInfo pi, MethodInfo accessor)
67 object [] attrs = accessor.GetCustomAttributes (typeof (AccessorCheckAttribute), true);
68 if (attrs == null)
69 return;
71 AccessorCheckAttribute accessor_attr = (AccessorCheckAttribute) attrs [0];
72 MethodAttributes accessor_flags = accessor.Attributes;
74 if ((accessor_flags & accessor_attr.Attributes) == accessor_attr.Attributes)
75 Console.WriteLine ("Test for {0}.{1} PASSED", pi.Name, accessor.Name);
76 else {
77 string message = String.Format ("Test for {0}.{1} INCORRECT: MethodAttributes should be {2}, but are {3}",
78 pi.Name, accessor.Name, accessor_attr.Attributes, accessor_flags);
79 throw new Exception (message);
85 [TypeCheck]
86 public class A {
88 const MethodAttributes flags = MethodAttributes.HideBySig |
89 MethodAttributes.SpecialName;
91 [PropertyCheck]
92 public int Value1 {
93 [AccessorCheck (flags | MethodAttributes.Public)]
94 get {
95 return 0;
97 [AccessorCheck (flags | MethodAttributes.Public)]
98 set {
102 [PropertyCheck]
103 public int Value2 {
104 [AccessorCheck (flags | MethodAttributes.Public)]
105 get {
106 return 0;
108 [AccessorCheck (flags | MethodAttributes.FamORAssem)]
109 protected internal set {
113 [PropertyCheck]
114 public int Value3 {
115 [AccessorCheck (flags | MethodAttributes.Public)]
116 get {
117 return 0;
119 [AccessorCheck (flags | MethodAttributes.Family)]
120 protected set {
124 [PropertyCheck]
125 public int Value4 {
126 [AccessorCheck (flags | MethodAttributes.Assembly)]
127 internal get {
128 return 0;
130 [AccessorCheck (flags | MethodAttributes.Public)]
131 set {
135 [PropertyCheck]
136 public int Value5 {
137 [AccessorCheck (flags | MethodAttributes.Public)]
138 get {
139 return 0;
141 [AccessorCheck (flags | MethodAttributes.Private)]
142 private set {