public void GetFieldFromHandle2_Incompatible() { RuntimeFieldHandle fh = typeof(FieldInfoTest <int>).GetField("TestField").FieldHandle; FieldInfoTest <string> instance = new FieldInfoTest <string> (); Type t2 = instance.GetType(); RuntimeTypeHandle th = t2.TypeHandle; FieldInfo fi2 = FieldInfo.GetFieldFromHandle(fh, th); }
[Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle) public void GetFieldFromHandle2_Handle_Generic() { FieldInfoTest <string> instance = new FieldInfoTest <string> (); Type t = instance.GetType(); FieldInfo fi1 = t.GetField("TestField"); RuntimeFieldHandle fh = fi1.FieldHandle; RuntimeTypeHandle th = t.TypeHandle; FieldInfo fi2 = FieldInfo.GetFieldFromHandle(fh, th); Assert.IsNotNull(fi2, "#1"); Assert.AreSame(t, fi2.DeclaringType, "#2"); Assert.AreEqual(typeof(string), fi2.FieldType, "#3"); Assert.AreEqual("TestField", fi2.Name, "#4"); }
public void NullableTests() { FieldInfoTest t = new FieldInfoTest(); FieldInfo fi = typeof(FieldInfoTest).GetField("nullable_field"); fi.SetValue(t, 101); Assert.AreEqual(101, fi.GetValue(t)); fi.SetValue(t, null); Assert.AreEqual(null, fi.GetValue(t)); FieldInfo fi2 = typeof(FieldInfoTest).GetField("static_nullable_field"); fi2.SetValue(t, 101); Assert.AreEqual(101, fi2.GetValue(t)); fi2.SetValue(t, null); Assert.AreEqual(null, fi2.GetValue(t)); }
public void NullableTests () { FieldInfoTest t = new FieldInfoTest (); FieldInfo fi = typeof (FieldInfoTest).GetField ("nullable_field"); fi.SetValue (t, 101); Assert.AreEqual (101, fi.GetValue (t)); fi.SetValue (t, null); Assert.AreEqual (null, fi.GetValue (t)); FieldInfo fi2 = typeof (FieldInfoTest).GetField ("static_nullable_field"); fi2.SetValue (t, 101); Assert.AreEqual (101, fi2.GetValue (t)); fi2.SetValue (t, null); Assert.AreEqual (null, fi2.GetValue (t)); }
public void GetFieldFromHandle2_Incompatible () { RuntimeFieldHandle fh = typeof (FieldInfoTest<int>).GetField ("TestField").FieldHandle; FieldInfoTest<string> instance = new FieldInfoTest<string> (); Type t2 = instance.GetType (); RuntimeTypeHandle th = t2.TypeHandle; FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th); }
[Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=343449 public void GetFieldFromHandle2_Handle_GenericDefinition () { Type t1 = typeof (FieldInfoTest<>); FieldInfo fi1 = t1.GetField ("TestField"); RuntimeFieldHandle fh = fi1.FieldHandle; FieldInfoTest<string> instance = new FieldInfoTest<string> (); Type t2 = instance.GetType (); RuntimeTypeHandle th = t2.TypeHandle; FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th); Assert.IsNotNull (fi2, "#1"); Assert.AreSame (t2, fi2.DeclaringType, "#2"); Assert.AreEqual (typeof (string), fi2.FieldType, "#3"); Assert.AreEqual ("TestField", fi2.Name, "#4"); }
public void TestSetValueArray () { var field = typeof (FieldInfoTest).GetField ("ObjectArrayField"); var instance = new FieldInfoTest (); field.SetValue (instance, new string[] { "3" }); field.SetValue (instance, null); Throws (field, instance, new int[] { 3 }); }