Exemplo n.º 1
0
        public static string GenerateArrayTypeLookup(Type type, TextGenerator gen)
        {
            type = type.Desugar();

            if (type is BuiltinType)
            {
                var builtinType = type as BuiltinType;
                return(GetMonoClassForPrimitiveType(builtinType.Type));
            }
            else if (type is CILType)
            {
                var cilType = type as CILType;

                if (cilType.Type == typeof(string))
                {
                    return("mono_get_string_class()");
                }

                return(string.Format("mono_m2n_search_class(\"{0}\", \"{1}\", \"{2}\")",
                                     cilType.Type.Assembly.GetName().Name, cilType.Type.Namespace,
                                     cilType.Type.Name));
            }
            else if (type is TagType)
            {
                var tagType = type as TagType;
                var decl    = tagType.Declaration;

                var @namespace = string.Empty;
                var ids        = string.Join(", ",
                                             decl.QualifiedName.Split('.').Select(n => string.Format("\"{0}\"", n)));

                var unit = decl.TranslationUnit;

                var classId       = string.Format("{0}_class", decl.QualifiedName);
                var monoImageName = string.Format("{0}_image", CGenerator.AssemblyId(unit));
                gen.WriteLine("{0} = mono_class_from_name({1}, \"{2}\", \"{3}\");",
                              classId, monoImageName, @namespace, decl.OriginalName);

                return(classId);
            }
            else if (type is ArrayType)
            {
                var arrayType = type as ArrayType;
                return("0");
            }

            throw new System.NotImplementedException();
        }