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
        public override void CreateGenerics()
        {
            Generics.Clear();
            GenericCallTypes.Clear();

            foreach (TypeSig t in AssociatedTypes)
            {
                if (!Generics.ContainsKey(t.ScopeType.MDToken.Raw))
                {
                    Generics.Add(t.ScopeType.MDToken.Raw,
                                 new GenericParamUser(
                                     (ushort)(TargetType.GenericParameters.Count + Generics.Count()),
                                     GenericParamAttributes.NoSpecialConstraint, GenericParamName)); //gen name
                    GenericCallTypes.Add(t);
                }
            }
        }