2 // Make sure that the field and accessor methods of an automatic property have the CompilerGenerated attribute
4 using System.Reflection;
5 using System.Runtime.CompilerServices;
6 using System.Diagnostics;
10 public string Foo { get; set; }
12 public static int Main ()
14 FieldInfo [] fields = typeof (Test).GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
15 if (!(fields.Length > 0))
17 object [] field_atts = fields[0].GetCustomAttributes (false);
18 if (field_atts.Length != 2)
20 if (field_atts[1].GetType() != typeof (DebuggerBrowsableAttribute))
22 if (field_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
25 if (fields [0].Name != "<Foo>k__BackingField")
28 PropertyInfo property = typeof (Test).GetProperty ("Foo");
29 MethodInfo get = property.GetGetMethod (false);
30 object [] get_atts = get.GetCustomAttributes (false);
31 if (!(get_atts.Length > 0))
33 if (get_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
36 MethodInfo set = property.GetSetMethod (false);
37 object [] set_atts = set.GetCustomAttributes (false);
38 if (!(set_atts.Length > 0))
40 if (set_atts[0].GetType() != typeof (CompilerGeneratedAttribute))