public void SetValue_MixedArrayTypes_Interface() { Type type = typeof(FI_FieldArray); object obj = Activator.CreateInstance(type); FieldInfo fieldInfo = GetField(type, "iArray"); FI_Interface[] mixedMN = new FI_Interface[] { new FI_ClassWithInterface1(), new FI_ClassWithInterface2() }; fieldInfo.SetValue(obj, mixedMN); Assert.Equal(mixedMN, fieldInfo.GetValue(obj)); }
public void SetValue_MixedArrayTypes_ObjectArray() { Type type = typeof(FI_FieldArray); object obj = Activator.CreateInstance(type); FieldInfo fieldInfo = GetField(type, "objectArray"); FI_Interface[] mixedMN = new FI_Interface[] { new FI_ClassWithInterface1(), new FI_ClassWithInterface2() }; fieldInfo.SetValue(obj, mixedMN); Assert.Equal(mixedMN, fieldInfo.GetValue(obj)); FI_BaseClass[] BTypeWithAllB_Contra = new FI_SubClass[] { new FI_SubClass(), new FI_SubClass() }; fieldInfo.SetValue(obj, BTypeWithAllB_Contra); Assert.Equal(BTypeWithAllB_Contra, fieldInfo.GetValue(obj)); AssertExtensions.Throws <ArgumentException>(null, () => fieldInfo.SetValue(obj, new int[] { 1, -1, 2, -2 })); AssertExtensions.Throws <ArgumentException>(null, () => fieldInfo.SetValue(obj, new byte[] { 2, 3, 4 })); }