private static void AppendNamespaceHashCode(ref HashCodeBuilder builder, NamespaceReferenceHandle namespaceRefHandle, MetadataReader reader)
        {
            NamespaceReference namespaceReference = reader.GetNamespaceReference(namespaceRefHandle);

            Handle parentHandle = namespaceReference.ParentScopeOrNamespace;
            HandleType parentHandleType = parentHandle.HandleType;
            if (parentHandleType == HandleType.NamespaceReference)
            {
                AppendNamespaceHashCode(ref builder, parentHandle.ToNamespaceReferenceHandle(reader), reader);
                string namespaceNamePart = reader.GetString(namespaceReference.Name);
                builder.Append(namespaceNamePart);
                builder.Append(".");
            }
            else
            {
                Debug.Assert(parentHandleType == HandleType.ScopeReference);
                Debug.Assert(String.IsNullOrEmpty(reader.GetString(namespaceReference.Name)), "Root namespace with a name?");
            }
        }
        public static int ComputeHashCode(this TypeDefinitionHandle typeDefHandle, MetadataReader reader)
        {
            HashCodeBuilder builder = new HashCodeBuilder("");

            TypeDefinition typeDef = reader.GetTypeDefinition(typeDefHandle);
            bool isNested = typeDef.Flags.IsNested();
            if (!isNested)
            {
                AppendNamespaceHashCode(ref builder, typeDef.NamespaceDefinition, reader);
            }

            string typeName = reader.GetString(typeDef.Name);
            builder.Append(typeName);

            if (isNested)
            {
                int enclosingTypeHashCode = typeDef.EnclosingType.ComputeHashCode(reader);
                return TypeHashingAlgorithms.ComputeNestedTypeHashCode(enclosingTypeHashCode, builder.ToHashCode());
            }

            return builder.ToHashCode();
        }
        public static int ComputeHashCode(this TypeReferenceHandle typeRefHandle, MetadataReader reader)
        {
            HashCodeBuilder builder = new HashCodeBuilder("");

            TypeReference typeRef = reader.GetTypeReference(typeRefHandle);
            HandleType parentHandleType = typeRef.ParentNamespaceOrType.HandleType;
            bool isNested = parentHandleType == HandleType.TypeReference;
            if (!isNested)
            {
                Debug.Assert(parentHandleType == HandleType.NamespaceReference);
                AppendNamespaceHashCode(ref builder, typeRef.ParentNamespaceOrType.ToNamespaceReferenceHandle(reader), reader);
            }

            string typeName = reader.GetString(typeRef.TypeName);
            builder.Append(typeName);

            if (isNested)
            {
                int enclosingTypeHashCode = typeRef.ParentNamespaceOrType.ToTypeReferenceHandle(reader).ComputeHashCode(reader);
                return TypeHashingAlgorithms.ComputeNestedTypeHashCode(enclosingTypeHashCode, builder.ToHashCode());
            }

            return builder.ToHashCode();
        }
        /// <summary>
        /// Try to figure out field access information based on type metadata for native format types.
        /// </summary>
        /// <param name="metadataReader">Metadata reader for the declaring type</param>
        /// <param name="declaringTypeHandle">Declaring type for the method</param>
        /// <param name="fieldHandle">Field handle</param>
        /// <param name="canonFormKind">Canonical form to use</param>
        /// <param name="fieldAccessMetadata">Output - metadata information for field accessor construction</param>
        /// <returns>true when found, false otherwise</returns>
        private static bool TryGetFieldAccessMetadataFromNativeFormatMetadata(
            MetadataReader metadataReader,
            RuntimeTypeHandle declaringTypeHandle,
            FieldHandle fieldHandle,
            TypeSystemContext context,
            ref FieldAccessMetadata fieldAccessMetadata)
        {
            Field field = metadataReader.GetField(fieldHandle);
            string fieldName = metadataReader.GetString(field.Name);

            TypeDesc declaringType = context.ResolveRuntimeTypeHandle(declaringTypeHandle);

#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
            if (declaringType is MetadataType)
            {
                return TryGetFieldAccessMetadataForNativeFormatType(declaringType, fieldName, ref fieldAccessMetadata);
            }
#endif

            return false;
        }