[generator] Add a TypeManager.GetUnderlyingNullableType to abstract away ikvm and reflection differences. (#1801)

Generator diff: https://gist.github.com/rolfbjarne/1ff230ac03cad6b81061c2814a5a895e
This commit is contained in:
Rolf Bjarne Kvinge 2017-03-01 14:59:52 +01:00 коммит произвёл GitHub
Родитель c93d1fb9e1
Коммит 0708ce5348
3 изменённых файлов: 11 добавлений и 6 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<NSString> (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);