Merge pull request #4935 from lambdageek/dev-handles-may
[mono.git] / mcs / tests / gtest-autoproperty-03.cs
1
2 // Make sure that the field and accessor methods of an automatic property have the CompilerGenerated attribute
3 using System;
4 using System.Reflection;
5 using System.Runtime.CompilerServices;
6 using System.Diagnostics;
7
8 public class Test
9 {
10         public string Foo { get; set; }
11         
12         public static int Main ()
13         {
14                 FieldInfo [] fields = typeof (Test).GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
15                 if (!(fields.Length > 0))
16                         return 1;
17                 object [] field_atts = fields[0].GetCustomAttributes (false);
18                 if (field_atts.Length != 2)
19                         return 2;
20                 if (field_atts[1].GetType() != typeof (DebuggerBrowsableAttribute))
21                         return 3;
22                 if (field_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
23                         return 4;
24                         
25                 if (fields [0].Name != "<Foo>k__BackingField")
26                         return 10;
27                 
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))
32                         return 4;
33                 if (get_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
34                         return 5;
35                         
36                 MethodInfo set = property.GetSetMethod (false);
37                 object [] set_atts = set.GetCustomAttributes (false);
38                 if (!(set_atts.Length > 0))
39                         return 6;
40                 if (set_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
41                         return 7;
42
43                 return 0;
44         }
45 }