Esempio n. 1
0
        internal bool RegisterGeneric(TypeSig t)
        {
            Debug.Assert(t != null, $"{nameof(t)} != null");

            // This is a temporary fix.
            // Type visibility should be handled in a much better way which would involved some analysis.
            var typeDef = t.ToTypeDefOrRef().ResolveTypeDef();

            if (typeDef != null && !typeDef.IsVisibleOutside())
            {
                return(false);
            }

            // Get proper type.
            t = SignatureUtils.GetLeaf(t);

            // scrambling voids leads to peverify errors, better leave them out.
            if (t.ElementType == ElementType.Void)
            {
                return(false);
            }

            if (!Generics.ContainsKey(t))
            {
                GenericParam newGenericParam;
                if (t.IsGenericMethodParameter)
                {
                    var mVar = t.ToGenericMVar();
                    Debug.Assert(mVar != null, $"{nameof(mVar)} != null");
                    newGenericParam = new GenericParamUser(GenericCount, mVar.GenericParam.Flags, $"T{GenericCount}")
                    {
                        Rid = mVar.Rid
                    };
                }
                else if (t.IsGenericTypeParameter)
                {
                    var tVar = t.ToGenericVar();
                    Debug.Assert(tVar != null, $"{nameof(tVar)} != null");
                    newGenericParam = new GenericParamUser(GenericCount, tVar.GenericParam.Flags, $"T{GenericCount}")
                    {
                        Rid = tVar.Rid
                    };
                }
                else
                {
                    newGenericParam = new GenericParamUser(GenericCount, GenericParamAttributes.NoSpecialConstraint, $"T{GenericCount}");
                }
                Generics.Add(t, newGenericParam);
                GenericCount++;
                _trueTypes.Add(t);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        internal GenericSig GetGeneric(TypeSig t)
        {
            Debug.Assert(t != null, $"{nameof(t)} != null");

            t = SignatureUtils.GetLeaf(t);

            GenericSig result = null;

            if (Generics.TryGetValue(t, out var gp))
            {
                result = this is ScannedType ? (GenericSig) new GenericVar(gp.Number) : new GenericMVar(gp.Number);
            }

            return(result);
        }
Esempio n. 3
0
        internal TypeSig UpdateSignature(TypeSig original)
        {
            var leaf = SignatureUtils.GetLeaf(original);

            if (leaf is TypeDefOrRefSig typeDefSig && typeDefSig.TypeDef != null)
            {
                var scannedDef = Service.GetItem(typeDefSig.TypeDef);
                if (scannedDef?.IsScambled == true)
                {
                    TypeSig newSig = scannedDef.CreateGenericTypeSig(null);
                    return(SignatureUtils.CopyModifiers(original, newSig));
                }
            }

            return(original);
        }