コード例 #1
0
 private static IReadOnlyDictionary<AnonymousTypeKey, AnonymousTypeValue> GetAnonymousTypeMap(
     MetadataReader reader,
     Symbols.Metadata.PE.MetadataDecoder metadataDecoder)
 {
     var result = new Dictionary<AnonymousTypeKey, AnonymousTypeValue>();
     foreach (var handle in reader.TypeDefinitions)
     {
         var def = reader.GetTypeDefinition(handle);
         if (!def.Namespace.IsNil)
         {
             continue;
         }
         if (!reader.StringStartsWith(def.Name, GeneratedNames.AnonymousNamePrefix))
         {
             continue;
         }
         var metadataName = reader.GetString(def.Name);
         short arity;
         var name = MetadataHelpers.InferTypeArityAndUnmangleMetadataName(metadataName, out arity);
         int index;
         if (GeneratedNames.TryParseAnonymousTypeTemplateName(name, out index))
         {
             var builder = ArrayBuilder<string>.GetInstance();
             if (TryGetAnonymousTypeKey(reader, def, builder))
             {
                 var type = (NamedTypeSymbol)metadataDecoder.GetTypeOfToken(handle);
                 var key = new AnonymousTypeKey(builder.ToImmutable());
                 var value = new AnonymousTypeValue(name, index, type);
                 result.Add(key, value);
             }
             builder.Free();
         }
     }
     return result;
 }
コード例 #2
0
        private IReadOnlyDictionary <AnonymousTypeKey, AnonymousTypeValue> MapAnonymousTypes(IReadOnlyDictionary <AnonymousTypeKey, AnonymousTypeValue> anonymousTypeMap)
        {
            Dictionary <AnonymousTypeKey, AnonymousTypeValue> result = new Dictionary <AnonymousTypeKey, AnonymousTypeValue>();

            foreach (KeyValuePair <AnonymousTypeKey, AnonymousTypeValue> pair in anonymousTypeMap)
            {
                AnonymousTypeKey    key   = pair.Key;
                AnonymousTypeValue  value = pair.Value;
                Cci.ITypeDefinition type  = (Cci.ITypeDefinition)MapDefinition(value.Type);
                Debug.Assert(type != null);
                result.Add(key, new AnonymousTypeValue(value.Name, value.UniqueIndex, type));
            }

            return(result);
        }