Skip to content

Commit

Permalink
fix(reg): Restore reflection extension support for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Feb 1, 2022
1 parent ea33cf2 commit ef9760c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ protected virtual IMemberDescriptor FindDescriptor(MemberInfo mi)
}
else
{
#if false // !WINDOWS_PHONE && !NETFX_CORE && !HAS_CRIPPLEDREFLECTION
#if !HAS_CRIPPLEDREFLECTION
return new FieldDescriptor(fieldInfo);
#else
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//
// ******************************************************************
#if false //!HAS_CRIPPLEDREFLECTION
#if !HAS_CRIPPLEDREFLECTION
using System;
using System.Reflection;
using System.Linq;
Expand Down Expand Up @@ -71,7 +71,8 @@ public FieldDescriptor(FieldInfo fi)
/// </remarks>
public static Action<object, object> ToCompiledSetValue(RuntimeTypeHandle typeHandle, RuntimeFieldHandle fieldHandle, bool strict)
{
var fieldInfo = FieldInfo.GetFieldFromHandle(fieldHandle, typeHandle);
#if NET6_0_OR_GREATER
var fieldInfo = FieldInfo.GetFieldFromHandle(fieldHandle, typeHandle);

if (fieldInfo.IsStatic || fieldInfo.DeclaringType.IsValueType)
{
Expand Down Expand Up @@ -110,7 +111,10 @@ public FieldDescriptor(FieldInfo fi)
il.Emit(OpCodes.Ret);

return method.CreateDelegate(typeof(Action<object, object>)) as Action<object, object>;
}
#else
throw new NotSupportedException($"ToCompiledSetValue is not supported on this platform");
#endif
}

/// <summary>
/// Creates a compiled method that will get the value of a field
Expand Down Expand Up @@ -144,6 +148,7 @@ public FieldDescriptor(FieldInfo fi)
/// </remarks>
public static Func<object, object> ToCompiledGetValue(RuntimeTypeHandle typeHandle, RuntimeFieldHandle fieldHandle, bool strict)
{
#if NET6_0_OR_GREATER
var fieldInfo = FieldInfo.GetFieldFromHandle(fieldHandle, typeHandle);

if (fieldInfo.IsStatic || fieldInfo.DeclaringType.IsValueType)
Expand Down Expand Up @@ -177,7 +182,10 @@ public FieldDescriptor(FieldInfo fi)
il.Emit(OpCodes.Ret);

return method.CreateDelegate(typeof(Func<object, object>)) as Func<object, object>;
}
}
#else
throw new NotSupportedException($"ToCompiledSetValue is not supported on this platform");
#endif
}
}
}
#endif

0 comments on commit ef9760c

Please sign in to comment.