Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorMaxim Lipnin <v-maxlip@microsoft.com>2018-09-07 02:04:50 +0300
committerMarek Safar <marek.safar@gmail.com>2018-09-07 09:57:03 +0300
commit2f8a6b5bdde89aa9617a303f248d9b4b6fef44af (patch)
treeb459eb1c3ff97151eeb25958bb31e28e6f9909c7 /mcs
parent64bfec630b5dd3180e1c5df5476f9436d62a71b6 (diff)
[System.Reflection] Make GetFieldOffset method virtual to fix issue with custom FieldInfo type.
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/corlib/System.Reflection.Emit/FieldOnTypeBuilderInst.cs5
-rw-r--r--mcs/class/corlib/System.Reflection/FieldInfo.cs5
-rw-r--r--mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs36
-rw-r--r--mcs/class/referencesource/mscorlib/system/runtime/serialization/serializationfieldinfo.cs5
4 files changed, 40 insertions, 11 deletions
diff --git a/mcs/class/corlib/System.Reflection.Emit/FieldOnTypeBuilderInst.cs b/mcs/class/corlib/System.Reflection.Emit/FieldOnTypeBuilderInst.cs
index c33e0f7f77b..9de89b1e2b8 100644
--- a/mcs/class/corlib/System.Reflection.Emit/FieldOnTypeBuilderInst.cs
+++ b/mcs/class/corlib/System.Reflection.Emit/FieldOnTypeBuilderInst.cs
@@ -128,11 +128,6 @@ namespace System.Reflection.Emit
throw new NotSupportedException ();
}
- internal override int GetFieldOffset ()
- {
- throw new SystemException ("This method should not be called");
- }
-
// Called from the runtime to return the corresponding finished FieldInfo object
internal FieldInfo RuntimeResolve () {
var type = instantiation.RuntimeResolve ();
diff --git a/mcs/class/corlib/System.Reflection/FieldInfo.cs b/mcs/class/corlib/System.Reflection/FieldInfo.cs
index 1a7528099da..747b021c9bc 100644
--- a/mcs/class/corlib/System.Reflection/FieldInfo.cs
+++ b/mcs/class/corlib/System.Reflection/FieldInfo.cs
@@ -59,7 +59,10 @@ namespace System.Reflection {
return fi;
}
- internal abstract int GetFieldOffset ();
+ internal virtual int GetFieldOffset ()
+ {
+ throw new SystemException ("This method should not be called");
+ }
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern MarshalAsAttribute get_marshal_info ();
diff --git a/mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs b/mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs
index 62680cc63a4..d21482dd20d 100644
--- a/mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs
+++ b/mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs
@@ -29,6 +29,7 @@
//
using System;
+using System.Globalization;
using System.Threading;
using System.Reflection;
#if !MONOTOUCH && !FULL_AOT_RUNTIME
@@ -1463,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
diff --git a/mcs/class/referencesource/mscorlib/system/runtime/serialization/serializationfieldinfo.cs b/mcs/class/referencesource/mscorlib/system/runtime/serialization/serializationfieldinfo.cs
index fccc00284c5..4281cdbd257 100644
--- a/mcs/class/referencesource/mscorlib/system/runtime/serialization/serializationfieldinfo.cs
+++ b/mcs/class/referencesource/mscorlib/system/runtime/serialization/serializationfieldinfo.cs
@@ -88,11 +88,6 @@ namespace System.Runtime.Serialization {
return m_field.FieldType;
}
}
-
- internal override int GetFieldOffset ()
- {
- throw new SystemException ("This method should not be called");
- }
public override Object GetValue(Object obj) {
return m_field.GetValue(obj);