Пример #1
0
        internal static unsafe SharpLangTypeGeneric ResolveGenericType(SharpLangEEType *eeType, SharpLangTypeDefinition genericTypeDefinition, SharpLangType[] genericArguments)
        {
            var genericTypeKey = new GenericKey(genericTypeDefinition, genericArguments);

            lock (SystemTypeLock)
            {
                SharpLangTypeGeneric sharpLangType;
                if (genericTypes.TryGetValue(genericTypeKey, out sharpLangType))
                {
                    return(sharpLangType);
                }

                if (eeType == null)
                {
                    var sharpLangTypeSearchKey = new SharpLangEETypeComparer.SharpLangTypeSearchKey
                    {
                        Kind           = SharpLangEEType.Kind.TypeDef,
                        TypeDefinition = new SharpLangEETypeDefinition
                        {
                            Module = genericTypeDefinition.InternalModule,
                            Handle = genericTypeDefinition.InternalHandle,
                        },
                        GenericArguments = genericArguments,
                    };
                    var typeIndex = SharpLangEETypeComparer.BinarySearch(types, ref sharpLangTypeSearchKey);
                    if (typeIndex >= 0)
                    {
                        eeType = types[typeIndex];
                    }
                }

                sharpLangType = new SharpLangTypeGeneric(eeType, genericTypeDefinition, genericArguments);
                genericTypes.Add(genericTypeKey, sharpLangType);

                if (eeType != null)
                {
                    eeType->CachedTypeField = (IntPtr)SharpLangHelper.GetObjectPointer(sharpLangType);
                }

                return(sharpLangType);
            }
        }
Пример #2
0
        internal unsafe SharpLangTypeDefinition ResolveTypeDef(SharpLangEEType *eeType, TypeDefinitionHandle typeDefHandle)
        {
            var typeDef = new SharpLangEETypeDefinition(this, typeDefHandle);

            lock (SystemTypeLock)
            {
                // Check if type has already been instantiated
                SharpLangTypeDefinition sharpLangType;
                if (typeDefinitions.TryGetValue(typeDef, out sharpLangType))
                {
                    return(sharpLangType);
                }

                if (eeType == null)
                {
                    var sharpLangTypeSearchKey = new SharpLangEETypeComparer.SharpLangTypeSearchKey
                    {
                        Kind           = SharpLangEEType.Kind.TypeDef,
                        TypeDefinition = typeDef,
                    };
                    var typeIndex = SharpLangEETypeComparer.BinarySearch(types, ref sharpLangTypeSearchKey);
                    if (typeIndex >= 0)
                    {
                        eeType = types[typeIndex];
                    }
                }

                sharpLangType = new SharpLangTypeDefinition(eeType, typeDef.Module, typeDef.Handle);
                typeDefinitions.Add(typeDef, sharpLangType);

                if (eeType != null)
                {
                    eeType->CachedTypeField = (IntPtr)SharpLangHelper.GetObjectPointer(sharpLangType);
                }

                return(sharpLangType);
            }
        }
Пример #3
0
        internal unsafe static SharpLangTypeElement ResolveElementType(SharpLangEEType *eeType, SharpLangType elementType, SharpLangEEType.Kind kind)
        {
            Dictionary <SharpLangType, SharpLangTypeElement> elementTypes;

            switch (kind)
            {
            case SharpLangEEType.Kind.Array:
                elementTypes = arrayTypes;
                break;

            case SharpLangEEType.Kind.Pointer:
                elementTypes = pointerTypes;
                break;

            case SharpLangEEType.Kind.ByRef:
                elementTypes = byRefTypes;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            lock (SystemTypeLock)
            {
                // Check if type has already been instantiated
                SharpLangTypeElement sharpLangType;
                if (elementTypes.TryGetValue(elementType, out sharpLangType))
                {
                    return(sharpLangType);
                }

                if (eeType == null)
                {
                    var sharpLangTypeSearchKey = new SharpLangEETypeComparer.SharpLangTypeSearchKey
                    {
                        Kind        = kind,
                        ElementType = elementType,
                    };
                    var typeIndex = SharpLangEETypeComparer.BinarySearch(types, ref sharpLangTypeSearchKey);
                    if (typeIndex >= 0)
                    {
                        eeType = types[typeIndex];
                    }
                }

                switch (kind)
                {
                case SharpLangEEType.Kind.Array:
                    sharpLangType = new SharpLangTypeArray(eeType, elementType, 1);
                    break;

                case SharpLangEEType.Kind.Pointer:
                    sharpLangType = new SharpLangTypePointer(eeType, elementType);
                    break;

                case SharpLangEEType.Kind.ByRef:
                    sharpLangType = new SharpLangTypeByRef(eeType, elementType);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                elementTypes.Add(elementType, sharpLangType);

                if (eeType != null)
                {
                    eeType->CachedTypeField = (IntPtr)SharpLangHelper.GetObjectPointer(sharpLangType);
                }

                return(sharpLangType);
            }
        }