Description
As a new reflection feature, a function pointer type will be a System.Type instance with new capabilities such as Type.IsFunctionPointer. Previously, the System.Type instance returned was the IntPtr type.
Using System.Type is this manner is similar to how other types are exposed such as pointers (Type.IsPointer) and arrays (Type.IsArray).
For more information, see the API issue and Design.
This new functionality is currently implemented in the CoreCLR runtime and in System.Reflection.MetadataLoadContext. Support for the Mono and NativeAOT runtimes are expected later.
A function pointer instance, which is a physical address to a function, continues to be represented as an IntPtr; only the reflection type was changed with this feature.
Version
.NET 8 Preview 2
Previous behavior
The IntPtr type was used for a function pointer type such as with typeof(delegate*<void>()) or when obtaining a function pointer type through reflection such as with FieldInfo.FieldType. This did not allow any access to the parameter types, return type or calling conventions.
New behavior
The System.Type is now used for a function pointer type with access to the parameter types, return type and calling conventions.
Type of breaking change
Reason for change
Adds the capability to obtain function pointer metadata including parameter types, the return type and the calling conventions. Function pointer support was added with C# 9 and .NET 6 but reflection support was not added at that time.
Recommended action
Any general-purpose reflection code that wants to support function pointers should use the new API Type.IsFunctionPointer if special treatment is required for function pointers.
Feature area
Other (please put exact area in description textbox)
Affected APIs
For function pointer types, the C# keyword typeof and these reflection APIs now return a Type instance with new capabilities\APIs instead of the semantics returned by the IntPtr type.
namespace System.Reflection
{
public abstract class FieldInfo
{
public Type FieldType() {get;}
}
public abstract class PropertyInfo
{
public Type PropertyType() {get;}
}
public abstract class ParameterInfo
{
public Type ParameterType() {get;}
}
}
Associated WorkItem - 70834
Description
As a new reflection feature, a function pointer type will be a
System.Typeinstance with new capabilities such asType.IsFunctionPointer. Previously, theSystem.Typeinstance returned was theIntPtrtype.Using
System.Typeis this manner is similar to how other types are exposed such as pointers (Type.IsPointer) and arrays (Type.IsArray).For more information, see the API issue and Design.
This new functionality is currently implemented in the CoreCLR runtime and in
System.Reflection.MetadataLoadContext. Support for the Mono and NativeAOT runtimes are expected later.A function pointer instance, which is a physical address to a function, continues to be represented as an
IntPtr; only the reflection type was changed with this feature.Version
.NET 8 Preview 2
Previous behavior
The
IntPtrtype was used for a function pointer type such as withtypeof(delegate*<void>())or when obtaining a function pointer type through reflection such as withFieldInfo.FieldType. This did not allow any access to the parameter types, return type or calling conventions.New behavior
The
System.Typeis now used for a function pointer type with access to the parameter types, return type and calling conventions.Type of breaking change
Reason for change
Adds the capability to obtain function pointer metadata including parameter types, the return type and the calling conventions. Function pointer support was added with C# 9 and .NET 6 but reflection support was not added at that time.
Recommended action
Any general-purpose reflection code that wants to support function pointers should use the new API
Type.IsFunctionPointerif special treatment is required for function pointers.Feature area
Other (please put exact area in description textbox)
Affected APIs
For function pointer types, the C# keyword
typeofand these reflection APIs now return aTypeinstance with new capabilities\APIs instead of the semantics returned by theIntPtrtype.Associated WorkItem - 70834