コード例 #1
0
ファイル: FieldInfoTest.cs プロジェクト: raj581/Marvin
        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);
        }
コード例 #2
0
ファイル: FieldInfoTest.cs プロジェクト: raj581/Marvin
        [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");
        }
コード例 #3
0
ファイル: FieldInfoTest.cs プロジェクト: raj581/Marvin
        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));
        }
コード例 #4
0
ファイル: FieldInfoTest.cs プロジェクト: bitslasher/mono
		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));
		}
コード例 #5
0
ファイル: FieldInfoTest.cs プロジェクト: bitslasher/mono
		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);
		}
コード例 #6
0
ファイル: FieldInfoTest.cs プロジェクト: bitslasher/mono
		[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");
		}
コード例 #7
0
ファイル: FieldInfoTest.cs プロジェクト: bitslasher/mono
		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 });
		}