//
using System;
+using System.Reflection;
using System.Runtime.CompilerServices;
namespace Mono {
}
}
}
+
+ internal struct RuntimeGenericParamInfoHandle {
+ unsafe RuntimeStructs.GenericParamInfo* value;
+
+ internal unsafe RuntimeGenericParamInfoHandle (RuntimeStructs.GenericParamInfo* value)
+ {
+ this.value = value;
+ }
+
+ internal unsafe RuntimeGenericParamInfoHandle (IntPtr ptr)
+ {
+ this.value = (RuntimeStructs.GenericParamInfo*) ptr;
+ }
+
+
+ internal Type[] Constraints { get { return GetConstraints (); } }
+
+ internal GenericParameterAttributes Attributes {
+ get {
+ unsafe {
+ return (GenericParameterAttributes) value->flags;
+ }
+ }
+ }
+
+ Type[] GetConstraints () {
+ int n = GetConstraintsCount ();
+ var a = new Type[n];
+ for (int i = 0; i < n; i++) {
+ unsafe {
+ RuntimeClassHandle c = new RuntimeClassHandle (value->constraints[i]);
+ a[i] = Type.GetTypeFromHandle (c.GetTypeHandle ());
+ }
+ }
+ return a;
+ }
+
+ int GetConstraintsCount () {
+ int i = 0;
+ unsafe {
+ RuntimeStructs.MonoClass** p = value->constraints;
+ while (p != null && *p != null) {
+ p++; i++;
+ }
+ }
+ return i;
+ }
+ }
}
internal struct MonoClass {
}
+
+ // class-internals.h MonoGenericParamInfo
+ internal unsafe struct GenericParamInfo {
+ internal MonoClass* pklass;
+ internal IntPtr name;
+ internal ushort flags;
+ internal uint token;
+ internal MonoClass** constraints; /* NULL terminated */
+ }
}
}
throw new InvalidOperationException(Environment.GetResourceString("Arg_NotGenericParameter"));
Contract.EndContractBlock();
- Type[] constraints = GetGenericParameterConstraints_impl ();
+ var paramInfo = new Mono.RuntimeGenericParamInfoHandle (RuntimeTypeHandle.GetGenericParameterInfo (this));
+ Type[] constraints = paramInfo.Constraints;
if (constraints == null)
constraints = EmptyArray<Type>.Value;
[MethodImplAttribute(MethodImplOptions.InternalCall)]
extern Type[] GetGenericArgumentsInternal (bool runtimeArray);
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern GenericParameterAttributes GetGenericParameterAttributes ();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- extern Type[] GetGenericParameterConstraints_impl ();
+ GenericParameterAttributes GetGenericParameterAttributes () {
+ return (new Mono.RuntimeGenericParamInfoHandle (RuntimeTypeHandle.GetGenericParameterInfo (this))).Attributes;
+ }
[MethodImplAttribute(MethodImplOptions.InternalCall)]
extern int GetGenericParameterPosition ();
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static bool IsGenericTypeDefinition (RuntimeType type);
+
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ internal extern static IntPtr GetGenericParameterInfo (RuntimeType type);
+
}
}
};
/* Additional details about a MonoGenericParam */
+/* Keep in sync with managed Mono.RuntimeStructs.GenericParamInfo */
typedef struct {
MonoClass *pklass; /* The corresponding `MonoClass'. */
const char *name;
ICALL(RT_3, "GetEvents_internal", ves_icall_RuntimeType_GetEvents_internal)
ICALL(RT_5, "GetFields_internal", ves_icall_RuntimeType_GetFields_internal)
ICALL(RT_6, "GetGenericArgumentsInternal", ves_icall_RuntimeType_GetGenericArguments)
-ICALL(RT_7, "GetGenericParameterAttributes", ves_icall_RuntimeType_GetGenericParameterAttributes)
-ICALL(RT_8, "GetGenericParameterConstraints_impl", ves_icall_RuntimeType_GetGenericParameterConstraints)
ICALL(RT_9, "GetGenericParameterPosition", ves_icall_RuntimeType_GetGenericParameterPosition)
ICALL(RT_10, "GetInterfaceMapData", ves_icall_RuntimeType_GetInterfaceMapData)
ICALL(RT_11, "GetInterfaces", ves_icall_RuntimeType_GetInterfaces)
ICALL(RTH_3, "GetAttributes", ves_icall_RuntimeTypeHandle_GetAttributes)
ICALL(RTH_4, "GetBaseType", ves_icall_RuntimeTypeHandle_GetBaseType)
ICALL(RTH_5, "GetElementType", ves_icall_RuntimeTypeHandle_GetElementType)
+ICALL(RTH_19, "GetGenericParameterInfo", ves_icall_RuntimeTypeHandle_GetGenericParameterInfo)
ICALL(RTH_6, "GetGenericTypeDefinition_impl", ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl)
ICALL(RTH_7, "GetMetadataToken", ves_icall_reflection_get_token)
ICALL(RTH_8, "GetModule", ves_icall_RuntimeTypeHandle_GetModule)
return -1;
}
-ICALL_EXPORT GenericParameterAttributes
-ves_icall_RuntimeType_GetGenericParameterAttributes (MonoReflectionType *type)
+ICALL_EXPORT MonoGenericParamInfo *
+ves_icall_RuntimeTypeHandle_GetGenericParameterInfo (MonoReflectionType *type)
{
- g_assert (IS_MONOTYPE (type));
- g_assert (is_generic_parameter (type->type));
- return (GenericParameterAttributes)mono_generic_param_info (type->type->data.generic_param)->flags;
-}
-
-ICALL_EXPORT MonoArray *
-ves_icall_RuntimeType_GetGenericParameterConstraints (MonoReflectionType *type)
-{
- MonoError error;
- MonoReflectionType *rt;
- MonoGenericParamInfo *param_info;
- MonoDomain *domain;
- MonoClass **ptr;
- MonoArray *res;
- int i, count;
-
- g_assert (IS_MONOTYPE (type));
-
- domain = mono_object_domain (type);
- param_info = mono_generic_param_info (type->type->data.generic_param);
- for (count = 0, ptr = param_info->constraints; ptr && *ptr; ptr++, count++)
- ;
-
- res = mono_array_new_checked (domain, mono_defaults.runtimetype_class, count, &error);
- if (mono_error_set_pending_exception (&error))
- return NULL;
- for (i = 0; i < count; i++) {
- rt = mono_type_get_object_checked (domain, ¶m_info->constraints [i]->byval_arg, &error);
- if (mono_error_set_pending_exception (&error))
- return NULL;
-
- mono_array_setref (res, i, rt);
- }
-
-
- return res;
+ return mono_generic_param_info (type->type->data.generic_param);
}
ICALL_EXPORT MonoBoolean