- public readonly Type Type;
- public readonly Type UnderlyingType;
- public MethodInfo HasValue;
- public MethodInfo Value;
- public MethodInfo GetValueOrDefault;
- public ConstructorInfo Constructor;
-
- public NullableInfo (Type type)
- {
- Type = type;
- UnderlyingType = TypeManager.GetTypeArguments (type) [0];
-
- PropertyInfo has_value_pi = TypeManager.GetPredefinedProperty (type, "HasValue", Location.Null, Type.EmptyTypes);
- PropertyInfo value_pi = TypeManager.GetPredefinedProperty (type, "Value", Location.Null, Type.EmptyTypes);
- GetValueOrDefault = TypeManager.GetPredefinedMethod (type, "GetValueOrDefault", Location.Null, Type.EmptyTypes);
-
- HasValue = has_value_pi.GetGetMethod (false);
- Value = value_pi.GetGetMethod (false);
-#if MS_COMPATIBLE
- if (UnderlyingType.Module == RootContext.ToplevelTypes.Builder) {
- Type o_type = TypeManager.DropGenericTypeArguments (type);
- Constructor = TypeBuilder.GetConstructor (type,
- TypeManager.GetPredefinedConstructor (o_type, Location.Null, o_type.GetGenericArguments ()));
- return;
- }
-#endif
- Constructor = type.GetConstructor (new Type[] { UnderlyingType });
+ public static MethodSpec GetConstructor (TypeSpec nullableType)
+ {
+ return TypeManager.GetPredefinedConstructor (nullableType, Location.Null, GetUnderlyingType (nullableType));
+ }
+
+ public static MethodSpec GetHasValue (TypeSpec nullableType)
+ {
+ return (MethodSpec) MemberCache.FindMember (nullableType,
+ MemberFilter.Method ("get_HasValue", 0, ParametersCompiled.EmptyReadOnlyParameters, null), BindingRestriction.None);
+ }
+
+ public static MethodSpec GetGetValueOrDefault (TypeSpec nullableType)
+ {
+ return (MethodSpec) MemberCache.FindMember (nullableType,
+ MemberFilter.Method ("GetValueOrDefault", 0, ParametersCompiled.EmptyReadOnlyParameters, null), BindingRestriction.None);
+ }
+
+ public static MethodSpec GetValue (TypeSpec nullableType)
+ {
+ return (MethodSpec) MemberCache.FindMember (nullableType,
+ MemberFilter.Method ("get_Value", 0, ParametersCompiled.EmptyReadOnlyParameters, null), BindingRestriction.None);
+ }
+
+ public static TypeSpec GetUnderlyingType (TypeSpec nullableType)
+ {
+ return ((InflatedTypeSpec) nullableType).TypeArguments[0];
+ }
+
+ public static bool IsNullableType (TypeSpec type)
+ {
+ throw new NotImplementedException ("net");