private static unsafe int Compare(SharpLangEETypeDefinition x, SharpLangEETypeDefinition y)
        {
            // Compare first by module, then token ID
            // TODO: Better to use something like assembly qualified name so that we can presort at compile time instead of runtime
            if ((void *)x.ModulePointer > (void *)y.ModulePointer)
            {
                return(1);
            }
            if ((void *)x.ModulePointer < (void *)y.ModulePointer)
            {
                return(-1);
            }

            return((*(uint *)&x.Handle).CompareTo(*(uint *)&y.Handle));
        }
Ejemplo n.º 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);
            }
        }