2 // PropertyInfoTest.cs - NUnit Test Cases for PropertyInfo
5 // Gert Driesen (drieseng@users.sourceforge.net)
11 using System.Reflection;
13 using NUnit.Framework;
15 namespace MonoTests.System.Reflection
18 public class PropertyInfoTest
21 public void GetAccessorsTest()
23 Type type = typeof(TestClass);
24 PropertyInfo property = type.GetProperty ("ReadOnlyProperty");
25 MethodInfo[] methods = property.GetAccessors (true);
27 Assert.AreEqual (1, methods.Length, "GetAccessors#1");
28 Assert.IsNotNull (methods[0], "GetAccessors#2");
36 public string Property {
37 get { return typeof (T).FullName; }
41 public int? nullable_field;
43 public int? NullableProperty {
44 get { return nullable_field; }
45 set { nullable_field = value; }
49 public void NullableTests ()
51 PropertyInfoTest t = new PropertyInfoTest ();
53 PropertyInfo pi = typeof(PropertyInfoTest).GetProperty("NullableProperty");
55 pi.SetValue (t, 100, null);
56 Assert.AreEqual (100, pi.GetValue (t, null));
57 pi.SetValue (t, null, null);
58 Assert.AreEqual (null, pi.GetValue (t, null));
62 public void Bug77160 ()
64 object instance = new A<string> ();
65 Type type = instance.GetType ();
66 PropertyInfo property = type.GetProperty ("Property");
67 Assert.AreEqual (typeof (string).FullName, property.GetValue (instance, null));
71 private class TestClass
73 public string ReadOnlyProperty
75 get { return string.Empty; }