Ejemplo n.º 1
0
        private ImportedType ImportType(TypeReference tref)
        {
            if (tref == null)
            {
                return(null);
            }
            switch (tref.MetadataType)
            {
            case MetadataType.Pointer:
            case MetadataType.Pinned:
            case MetadataType.Array:
                ImportType(tref.GetElementType());
                return(null);

            case MetadataType.OptionalModifier:
            case MetadataType.RequiredModifier:

            case MetadataType.ByReference:
                return(ImportType(tref.GetElementType()));

            case MetadataType.Boolean:
            case MetadataType.Byte:
            case MetadataType.Char:
            case MetadataType.Double:
            case MetadataType.FunctionPointer:
            case MetadataType.GenericInstance:
            case MetadataType.Int16:
            case MetadataType.Int32:
            case MetadataType.Int64:
            case MetadataType.IntPtr:
            case MetadataType.MVar:
            case MetadataType.Object:
            case MetadataType.SByte:
            case MetadataType.Single:
            case MetadataType.String:
            case MetadataType.UInt16:
            case MetadataType.UInt32:
            case MetadataType.UInt64:
            case MetadataType.UIntPtr:
            case MetadataType.ValueType:
            case MetadataType.Var:
            case MetadataType.Void:
            case MetadataType.TypedByReference:
                return(null);
            }
            if (tref is GenericInstanceType)
            {
                GenericInstanceType gt = (GenericInstanceType)tref;
                for (int i = 0; i < gt.GenericArguments.Count; i++)
                {
                    ImportType(gt.GenericArguments[i]);
                }
                if (gt.ElementType is TypeDefinition)
                {
                    return(null);
                }
                tref = gt.ElementType;
            }
            if (tref is TypeDefinition)
            {
                return(null);
            }
            if (typeCache.ContainsKey(tref))
            {
                return(typeCache[tref]);
            }
            if (Program.IsFiltered(tref))
            {
                return(null);
            }
            var mod = output.library.Where(a => a.name == tref.Scope.Name).FirstOrDefault();

            if (mod == null)
            {
                mod          = new ImportedLibrary();
                mod.name     = tref.Scope.Name;
                mod.fullname = tref.Module.AssemblyReferences.Where(a => a.Name == tref.Scope.Name).FirstOrDefault().FullName;
                output.library.Add(mod);
            }
            var it = new ImportedType();

            it.name = tref.ToString();
            mod.type.Add(it);
            typeCache.Add(tref, it);
            return(it);
        }
Ejemplo n.º 2
0
        private ImportedType ImportType(TypeReference tref)
        {
            if (tref == null) return null;
            switch (tref.MetadataType)
            {
                case MetadataType.Pointer:
                case MetadataType.Pinned:
                case MetadataType.Array:
                    ImportType(tref.GetElementType());
                    return null;
                    case MetadataType.OptionalModifier:
                case MetadataType.RequiredModifier:

                case MetadataType.ByReference:
                    return ImportType(tref.GetElementType());
                case MetadataType.Boolean:
                case MetadataType.Byte:
                case MetadataType.Char:
                case MetadataType.Double:
                case MetadataType.FunctionPointer:
                case MetadataType.GenericInstance:
                case MetadataType.Int16:
                case MetadataType.Int32:
                case MetadataType.Int64:
                case MetadataType.IntPtr:
                case MetadataType.MVar:
                case MetadataType.Object:
                case MetadataType.SByte:
                case MetadataType.Single:
                case MetadataType.String:
                case MetadataType.UInt16:
                case MetadataType.UInt32:
                case MetadataType.UInt64:
                case MetadataType.UIntPtr:
                case MetadataType.ValueType:
                case MetadataType.Var:
                case MetadataType.Void:
                case MetadataType.TypedByReference:
                    return null;
            }
            if (tref is GenericInstanceType)
            {
                GenericInstanceType gt = (GenericInstanceType)tref;
                for (int i = 0; i < gt.GenericArguments.Count; i++)
                    ImportType(gt.GenericArguments[i]);
                if (gt.ElementType is TypeDefinition) return null;
                tref = gt.ElementType;
            }
            if (tref is TypeDefinition) return null;
            if (typeCache.ContainsKey(tref)) return typeCache[tref];
            if (Program.IsFiltered(tref)) return null;
            var mod = output.library.Where(a => a.name == tref.Scope.Name).FirstOrDefault();
            if (mod == null)
            {
                mod = new ImportedLibrary();
                mod.name = tref.Scope.Name;
                mod.fullname = tref.Module.AssemblyReferences.Where(a => a.Name == tref.Scope.Name).FirstOrDefault().FullName;
                output.library.Add(mod);
            }
            var it = new ImportedType();
            it.name = tref.ToString();
            mod.type.Add(it);
            typeCache.Add(tref, it);
            return it;
        }