Esempio n. 1
0
        public ILType GetType(Type clrType)
        {
            if (clrType == null)
            {
                return(null);
            }
            lock (this)
            {
                ILType type;
                if (TypeToILType.TryGetValue(clrType, out type))
                {
                    return(type);
                }

                type = CLRType.Create(clrType, this);
                return(CacheTypeInternal(type));
            }
        }
        private ILType CreateTypeInternal(ITypeSymbol symbol)
        {
            var pointerSymbol = symbol as PointerSymbol;

            if (pointerSymbol != null)
            {
                var element = GetTypeInternal(pointerSymbol.Element);
                if (element == null)
                {
                    return(null);
                }
                var type = element.CreatePointerType();
                return(CacheTypeInternal(type));
            }

            var refSymbol = symbol as RefSymbol;

            if (refSymbol != null)
            {
                var element = GetTypeInternal(refSymbol.Element);
                if (element == null)
                {
                    return(null);
                }
                var type = element.CreateByRefType();
                return(CacheTypeInternal(type));
            }

            var arraySymbol = symbol as ArraySymbol;

            if (arraySymbol != null)
            {
                var element = GetTypeInternal(arraySymbol.Element);
                if (element == null)
                {
                    return(null);
                }
                var type = element.CreateArrayType(arraySymbol.Rank);
                return(CacheTypeInternal(type));
            }

            var genericSymbol = symbol as GenericSymbol;

            if (genericSymbol != null)
            {
                var elementType = GetTypeInternal(genericSymbol.Element);
                if (elementType == null)
                {
                    return(null);
                }

                var genericArugments = new FastList <ILType>(genericSymbol.GenericParameters.Count);
                foreach (var generic in genericSymbol.GenericParameters)
                {
                    var genericType = GetTypeInternal(generic);
                    if (genericType == null)
                    {
                        return(null);
                    }
                    genericArugments.Add(genericType);
                }

                var type = elementType.CreateGenericType(genericArugments);
                return(CacheTypeInternal(type));
            }

            var nameSymbol = symbol as NameSymbol;

            if (nameSymbol != null)
            {
                var clr = TypeSupport.GetType(nameSymbol.AssemblyQualifiedName);
                if (clr == null)
                {
                    return(null);
                }
                var type = CLRType.Create(clr, this);
                return(CacheTypeInternal(type));
            }
            return(null);
        }