Example #1
0
        public static System.Type GetSystemType(BindingContext context, Type type)
        {
            if (context.TypeMaps.FindTypeMap(type, out TypeMap typeMap))
            {
                var cilType = typeMap.CSharpSignatureType(new TypePrinterContext {
                    Type = type, Kind = TypePrinterContextKind.Managed
                }) as CILType;
                if (cilType != null)
                {
                    return(cilType.Type);
                }
            }

            if (type is BuiltinType builtInType)
            {
                if (builtInType.Type == PrimitiveType.Float)
                {
                    return(typeof(float));
                }
                else if (builtInType.Type == PrimitiveType.Double)
                {
                    return(typeof(double));
                }

                try
                {
                    CSharpTypePrinter.GetPrimitiveTypeWidth(builtInType.Type, context.TargetInfo, out var w, out var signed);
                    var cilType = (signed ? CSharpTypePrinter.GetSignedType(w) : CSharpTypePrinter.GetUnsignedType(w)) as CILType;
                    if (cilType != null)
                    {
                        return(cilType.Type);
                    }
                }
                catch
                {
                    return(null);
                }
            }

            return(null);
        }
Example #2
0
 public override Type CSharpSignatureType(TypePrinterContext ctx) =>
 CSharpTypePrinter.GetSignedType(Context.TargetInfo.LongWidth);