using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
+#if !MONOTOUCH
using System.Reflection.Emit;
+#endif
using System.IO;
using NUnit.Framework;
{
Type type = typeof (TestClass);
PropertyInfo property = type.GetProperty ("ReadOnlyProperty");
+ Assert.IsNotNull (property.Module, "#0");
MethodInfo [] methods = property.GetAccessors (true);
Assert.AreEqual (1, methods.Length, "#A1");
methods = property.GetAccessors ();
Assert.AreEqual (0, methods.Length, "#H");
-#if NET_2_0
property = typeof (TestClass).GetProperty ("PrivateSetter");
methods = property.GetAccessors (true);
Assert.AreEqual (1, methods.Length, "#J1");
Assert.IsNotNull (methods [0], "#J2");
Assert.AreEqual ("get_PrivateSetter", methods [0].Name, "#J3");
-#endif
}
[Test]
get { return 99; }
}
}
-
+#if !MONOTOUCH
[Test]
public void ConstantValue () {
/*This test looks scary because we can't generate a default value with C# */
} catch (InvalidOperationException) {
}
}
+#endif
-#if NET_2_0
public class A<T>
{
public string Property {
PropertyInfo property = type.GetProperty ("Property");
Assert.AreEqual (typeof (string).FullName, property.GetValue (instance, null));
}
-#endif
+ [Test]
+ public void ToStringTest ()
+ {
+ var pa = typeof (TestC).GetProperty ("Item");
+ Assert.AreEqual ("Int32 Item [Double[]]", pa.ToString ());
+ }
static bool HasAttribute (object [] attrs, Type attributeType)
{
set { }
}
-#if NET_2_0
public string PrivateSetter {
get { return null; }
private set { }
}
-#endif
}
[Test] // bug #633671
Assert.AreEqual (typeof (ClassWithNullableDateTime), siblingProperty.DeclaringType, "#3");
Assert.AreEqual (typeof (InheritsFromClassWithNullableDateTime), siblingProperty.ReflectedType, "#4");
}
-
-
+
+ class Super { public long A { get; private set; } }
+
+ class Sub : Super { }
+
+ [Test]
+ public void PrivateSetterFromDerivedType ()
+ {
+ var prop = typeof (Sub).GetProperty ("A");
+ Assert.AreEqual (1, prop.GetAccessors (true).Length, "#1");
+ Assert.IsFalse (prop.CanWrite, "#2");
+ Assert.IsNull (prop.GetSetMethod (true), "#3");
+ }
+
public class ClassWithNullableDateTime
{
public DateTime? Property1 { get; set; }
public class InheritsFromClassWithNullableDateTime : ClassWithNullableDateTime
{
}
+
+ public static int ThrowingProperty {
+ get {
+ throw new ObjectDisposedException("TestClass");
+ }
+ }
+
+ [Test]
+ public void GetException () {
+ var prop = typeof(PropertyInfoTest).GetProperty("ThrowingProperty");
+ try {
+ prop.GetValue (null, null);
+ Assert.Fail ();
+ } catch (TargetInvocationException ex) {
+ Assert.IsTrue (ex.InnerException is ObjectDisposedException);
+ }
+ }
+
+ public class DefaultValueTest
+ {
+ public string this[int val, string param = "test"]
+ {
+ get{ return val + param; }
+ }
+ }
+
+
+ [Test]
+ public void PropertyWithDefaultValue ()
+ {
+ var parameters = typeof (DefaultValueTest).GetProperty ("Item").GetIndexParameters ();
+ var defaultParam = parameters[parameters.Length - 1];
+ Assert.AreEqual ("param", defaultParam.Name, "#1");
+ Assert.AreEqual ("test", defaultParam.DefaultValue, "#2");
+ }
}
}