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;
9 public string Foo { get; set; }
13 FieldInfo [] fields = typeof (Test).GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
14 if (!(fields.Length > 0))
16 object [] field_atts = fields[0].GetCustomAttributes (false);
17 if (!(field_atts.Length > 0))
19 if (field_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
22 if (fields [0].Name != "<Foo>k__BackingField")
25 PropertyInfo property = typeof (Test).GetProperty ("Foo");
26 MethodInfo get = property.GetGetMethod (false);
27 object [] get_atts = get.GetCustomAttributes (false);
28 if (!(get_atts.Length > 0))
30 if (get_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
33 MethodInfo set = property.GetSetMethod (false);
34 object [] set_atts = set.GetCustomAttributes (false);
35 if (!(set_atts.Length > 0))
37 if (set_atts[0].GetType() != typeof (CompilerGeneratedAttribute))