You've already forked linux-packaging-mono
Imported Upstream version 5.20.0.180
Former-commit-id: ff953ca879339fe1e1211f7220f563e1342e66cb
This commit is contained in:
parent
0e2d47d1c8
commit
0510252385
@ -29,6 +29,7 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Reflection;
|
||||
#if !MONOTOUCH && !FULL_AOT_RUNTIME
|
||||
@ -224,6 +225,14 @@ namespace MonoTests.System.Reflection
|
||||
Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D10");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MetadataToken ()
|
||||
{
|
||||
Type type = typeof (FieldInfoTest);
|
||||
FieldInfo field = type.GetField ("i");
|
||||
Assert.IsTrue ((int)field.MetadataToken > 0);
|
||||
}
|
||||
|
||||
[Test] // GetFieldFromHandle (RuntimeFieldHandle)
|
||||
public void GetFieldFromHandle1_Handle_Zero ()
|
||||
{
|
||||
@ -1455,6 +1464,41 @@ namespace MonoTests.System.Reflection
|
||||
public const FieldInfoTest object_field = null;
|
||||
public int non_const_field;
|
||||
|
||||
class FieldInfoWrapper : FieldInfo
|
||||
{
|
||||
private FieldInfo fieldInfo;
|
||||
|
||||
public FieldInfoWrapper (FieldInfo fieldInfo)
|
||||
{
|
||||
this.fieldInfo = fieldInfo;
|
||||
}
|
||||
|
||||
public override FieldAttributes Attributes => fieldInfo.Attributes;
|
||||
public override Type DeclaringType => fieldInfo.DeclaringType;
|
||||
public override RuntimeFieldHandle FieldHandle => fieldInfo.FieldHandle;
|
||||
public override Type FieldType => fieldInfo.FieldType;
|
||||
public override string Name => fieldInfo.Name;
|
||||
public override Type ReflectedType => fieldInfo.ReflectedType;
|
||||
|
||||
public override object[] GetCustomAttributes (bool inherit) => fieldInfo.GetCustomAttributes (inherit);
|
||||
public override object[] GetCustomAttributes (Type attributeType, bool inherit) => fieldInfo.GetCustomAttributes (attributeType, inherit);
|
||||
public override object GetValue (object obj) => fieldInfo.GetValue (obj);
|
||||
public override bool IsDefined (Type attributeType, bool inherit) => fieldInfo.IsDefined (attributeType, inherit);
|
||||
public override void SetValue (object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) =>
|
||||
fieldInfo.SetValue (obj, value, invokeAttr, binder, culture);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CustomFieldInfo ()
|
||||
{
|
||||
var fieldInfoWrapper = new FieldInfoWrapper (GetType ().GetField (nameof (non_const_field)));
|
||||
MethodInfo method = typeof (FieldInfoWrapper).GetMethod ("GetFieldOffset", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
Assert.IsNotNull (method);
|
||||
Assert.IsTrue (method.IsVirtual);
|
||||
|
||||
var ex = Assert.Catch<Exception> (() => method.Invoke (fieldInfoWrapper, new object[] {}));
|
||||
Assert.IsTrue (ex.InnerException is SystemException);
|
||||
}
|
||||
}
|
||||
|
||||
// We do not refernece the field, that is expected
|
||||
|
Reference in New Issue
Block a user