diff --git a/src/generator-attributes.cs b/src/generator-attributes.cs index db897fd39e..0ee1228290 100644 --- a/src/generator-attributes.cs +++ b/src/generator-attributes.cs @@ -85,7 +85,7 @@ public class BindAsAttribute : Attribute { public BindAsAttribute (Type type) { Type = type; - var nullable = type.IsArray ? Nullable.GetUnderlyingType (type.GetElementType ()) : Nullable.GetUnderlyingType (type); + var nullable = type.IsArray ? TypeManager.GetUnderlyingNullableType (type.GetElementType ()) : TypeManager.GetUnderlyingNullableType (type); IsNullable = nullable != null; IsValueType = IsNullable ? nullable.IsValueType : type.IsValueType; } diff --git a/src/generator-typemanager.cs b/src/generator-typemanager.cs index 11b7a32f7c..635a4f165d 100644 --- a/src/generator-typemanager.cs +++ b/src/generator-typemanager.cs @@ -225,6 +225,11 @@ public static class TypeManager { return rv; } + public static Type GetUnderlyingNullableType (Type type) + { + return Nullable.GetUnderlyingType (type); + } + public static bool IsOutParameter (ParameterInfo pi) { return AttributeManager.HasAttribute (pi, OutAttribute); diff --git a/src/generator.cs b/src/generator.cs index e60117976a..bee2a1bd45 100644 --- a/src/generator.cs +++ b/src/generator.cs @@ -1218,7 +1218,7 @@ public partial class Generator : IMemberGatherer { originalType = pi.ParameterType; } - var retType = Nullable.GetUnderlyingType (attrib.Type) ?? attrib.Type; + var retType = TypeManager.GetUnderlyingNullableType (attrib.Type) ?? attrib.Type; var isNullable = attrib.IsNullable; var isValueType = retType.IsValueType; var isEnum = retType.IsEnum; @@ -1246,7 +1246,7 @@ public partial class Generator : IMemberGatherer { temp = string.Format ("{1}{0}.GetConstant ();", denullify, parameterName); } else if (originalType.IsArray) { var arrType = originalType.GetElementType (); - var arrRetType = Nullable.GetUnderlyingType (retType.GetElementType ()) ?? retType.GetElementType (); + var arrRetType = TypeManager.GetUnderlyingNullableType (retType.GetElementType ()) ?? retType.GetElementType (); var valueConverter = string.Empty; if (arrType == TypeManager.NSString) @@ -1347,7 +1347,7 @@ public partial class Generator : IMemberGatherer { throw new BindingException (1050, true, "[BindAs] cannot be used inside Protocol or Model types. Type: {0}", declaringType.Name); var attrib = GetBindAsAttribute (minfo.mi); - var retType = Nullable.GetUnderlyingType (attrib.Type) ?? attrib.Type; + var retType = TypeManager.GetUnderlyingNullableType (attrib.Type) ?? attrib.Type; var isValueType = retType.IsValueType; var append = string.Empty; var property = minfo.mi as PropertyInfo; @@ -1376,7 +1376,7 @@ public partial class Generator : IMemberGatherer { append = $"{FormatType (retType.DeclaringType, retType)}Extensions.GetValue ("; } else if (originalReturnType.IsArray) { var arrType = originalReturnType.GetElementType (); - var arrRetType = Nullable.GetUnderlyingType (retType.GetElementType ()) ?? retType.GetElementType (); + var arrRetType = TypeManager.GetUnderlyingNullableType (retType.GetElementType ()) ?? retType.GetElementType (); var valueFetcher = string.Empty; if (arrType == TypeManager.NSString) append = $"ptr => {{\n\tusing (var str = Runtime.GetNSObject (ptr)) {{\n\t\treturn {FormatType (arrRetType.DeclaringType, arrRetType)}Extensions.GetValue (str);\n\t}}\n}}"; @@ -3342,7 +3342,7 @@ public partial class Generator : IMemberGatherer { cast_b = "))"; } else { var bindAs = GetBindAsAttribute (minfo.mi); - var bindAsType = Nullable.GetUnderlyingType (bindAs.Type) ?? bindAs.Type; + var bindAsType = TypeManager.GetUnderlyingNullableType (bindAs.Type) ?? bindAs.Type; var enumCast = (bindAsType.IsEnum && !minfo.type.IsArray) ? $"({FormatType (bindAsType.DeclaringType, GetCorrectGenericType (bindAsType))})" : string.Empty; cast_a = $" {enumCast}Runtime.GetNSObject<{FormatType (declaringType, GetCorrectGenericType (mi.ReturnType))}> ("; cast_b = ")" + GetFromBindAsWrapper (minfo);