Exemplo n.º 1
0
        private static TypeSig ReferenceType(TypeSig type, ModuleDef module)
        {
            if (type == null)
                return null;

            if (type.IsSZArray)
            {
                var szar = type.ToSZArraySig();
                var eleType = ReferenceType(szar.Next, module);
                if (eleType == null)
                    return null;
                return new SZArraySig(eleType);
            }
            
            if (type.IsArray)
            {
                var ar = type.ToArraySig();
                var eleType = ReferenceType(ar.Next, module);
                if (eleType == null)
                    return null;
                return new ArraySig(eleType, ar.Rank, ar.Sizes, ar.LowerBounds);
            }

            if (type.IsGenericInstanceType)
            {
                var g = type.ToGenericInstSig();

                var gtype = FindType(g.GenericType.FullName, module);
                ClassOrValueTypeSig ngt;
                if (gtype == null)
                    ngt = g.GenericType;
                else  
                    ngt = gtype.TryGetClassOrValueTypeSig();

                TypeSig[] genericArgs = new TypeSig[g.GenericArguments.Count];
                for (int i = 0; i < g.GenericArguments.Count; ++i)
                {
                    var subArg = ReferenceType(g.GenericArguments[i], module);
                    if (subArg != null)
                        genericArgs[i] = subArg;
                    else
                        genericArgs[i] = g.GenericArguments[i];
                }

                return new GenericInstSig(ngt, genericArgs);
            }

            var targetType = FindType(type.FullName, module);
            if (targetType == null)
                return null;

            return targetType.ToTypeSig();
        }