3 // We use reflection to test that the flags are the correct ones
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
)
34 public MethodAttributes Attributes
{
43 public static int Main (string [] args
)
47 foreach (PropertyInfo pi
in t
.GetProperties ()) {
48 object [] attrs
= pi
.GetCustomAttributes (typeof (PropertyCheckAttribute
), true);
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
);
65 static void CheckFlags (PropertyInfo pi
, MethodInfo accessor
)
67 object [] attrs
= accessor
.GetCustomAttributes (typeof (AccessorCheckAttribute
), true);
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
);
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
);
88 const MethodAttributes flags
= MethodAttributes
.HideBySig
|
89 MethodAttributes
.SpecialName
;
93 [AccessorCheck (flags
| MethodAttributes
.Public
)]
97 [AccessorCheck (flags
| MethodAttributes
.Public
)]
104 [AccessorCheck (flags
| MethodAttributes
.Public
)]
108 [AccessorCheck (flags
| MethodAttributes
.FamORAssem
)]
109 protected internal set {
115 [AccessorCheck (flags
| MethodAttributes
.Public
)]
119 [AccessorCheck (flags
| MethodAttributes
.Family
)]
126 [AccessorCheck (flags
| MethodAttributes
.Assembly
)]
130 [AccessorCheck (flags
| MethodAttributes
.Public
)]
137 [AccessorCheck (flags
| MethodAttributes
.Public
)]
141 [AccessorCheck (flags
| MethodAttributes
.Private
)]