提交 7d668335 编写于 作者: C Charles Stoner

Incorporate PR feedback

上级 9123539b
......@@ -525,7 +525,7 @@ internal bool TryFindAnonymousType(NamedTypeSymbol type, out AnonymousTypeValue
Debug.Assert((object)type.ContainingSymbol == (object)_sourceAssembly.GlobalNamespace);
Debug.Assert(AnonymousTypeManager.IsAnonymousTypeTemplate(type));
var key = new AnonymousTypeKey(AnonymousTypeManager.GetTemplatePropertyNames(type));
var key = AnonymousTypeManager.GetAnonymousTypeKey(type);
return _anonymousTypeMap.TryGetValue(key, out otherType);
}
......
......@@ -366,9 +366,9 @@ public void AssignTemplatesNamesAndCompile(MethodCompiler compiler, PEModuleBuil
}
}
internal static ImmutableArray<string> GetTemplatePropertyNames(NamedTypeSymbol type)
internal static Microsoft.CodeAnalysis.Emit.AnonymousTypeKey GetAnonymousTypeKey(NamedTypeSymbol type)
{
return ((AnonymousTypeTemplateSymbol)type).GetPropertyNames();
return ((AnonymousTypeTemplateSymbol)type).GetAnonymousTypeKey();
}
internal IReadOnlyDictionary<Microsoft.CodeAnalysis.Emit.AnonymousTypeKey, Microsoft.CodeAnalysis.Emit.AnonymousTypeValue> GetAnonymousTypeMap()
......@@ -378,7 +378,7 @@ internal static ImmutableArray<string> GetTemplatePropertyNames(NamedTypeSymbol
foreach (AnonymousTypeTemplateSymbol template in templates)
{
var nameAndIndex = template.NameAndIndex;
var key = new Microsoft.CodeAnalysis.Emit.AnonymousTypeKey(template.GetPropertyNames());
var key = template.GetAnonymousTypeKey();
var value = new Microsoft.CodeAnalysis.Emit.AnonymousTypeValue(nameAndIndex.Name, nameAndIndex.Index, template);
result.Add(key, value);
}
......
......@@ -131,9 +131,10 @@ internal AnonymousTypeTemplateSymbol(AnonymousTypeManager manager, AnonymousType
this.SpecialMembers = specialMembers.AsImmutable();
}
internal ImmutableArray<string> GetPropertyNames()
internal Microsoft.CodeAnalysis.Emit.AnonymousTypeKey GetAnonymousTypeKey()
{
return this.Properties.SelectAsArray(p => p.Name);
var properties = this.Properties.SelectAsArray(p => new Microsoft.CodeAnalysis.Emit.AnonymousTypeKeyField(p.Name));
return new Microsoft.CodeAnalysis.Emit.AnonymousTypeKey(properties);
}
/// <summary>
......
......@@ -11,10 +11,17 @@ namespace Microsoft.CodeAnalysis.Emit
{
internal struct AnonymousTypeKeyField : IEquatable<AnonymousTypeKeyField>
{
/// <summary>
/// Name of the anonymous type field.
/// </summary>
internal readonly string Name;
/// <summary>
/// True if the anonymous type field was marked as 'Key' in VB.
/// </summary>
internal readonly bool IsKey;
internal AnonymousTypeKeyField(string name, bool isKey)
internal AnonymousTypeKeyField(string name, bool isKey = false)
{
this.Name = name;
this.IsKey = isKey;
......@@ -44,15 +51,10 @@ public override string ToString()
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
internal struct AnonymousTypeKey : IEquatable<AnonymousTypeKey>
{
public readonly bool IsDelegate;
public readonly ImmutableArray<AnonymousTypeKeyField> Fields;
public AnonymousTypeKey(ImmutableArray<string> names)
{
throw new NotImplementedException();
}
internal readonly bool IsDelegate;
internal readonly ImmutableArray<AnonymousTypeKeyField> Fields;
public AnonymousTypeKey(ImmutableArray<AnonymousTypeKeyField> fields, bool isDelegate = false)
internal AnonymousTypeKey(ImmutableArray<AnonymousTypeKeyField> fields, bool isDelegate = false)
{
this.IsDelegate = isDelegate;
this.Fields = fields;
......
......@@ -116,6 +116,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Debug.Assert(typeParameter.ContainingSymbol = type)
Dim index = typeParameter.Ordinal
Debug.Assert(properties(index).Name Is Nothing)
' ReadOnly anonymous type properties were 'Key' properties.
properties(index) = New AnonymousTypeKeyField([property].Name, [property].IsReadOnly)
End If
Next
......@@ -134,8 +135,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Dim method = DirectCast(members(0), MethodSymbol)
Debug.Assert(method.Parameters.Count + If(method.IsSub, 0, 1) = type.TypeParameters.Length)
Dim parameters = ArrayBuilder(Of AnonymousTypeKeyField).GetInstance()
parameters.AddRange(method.Parameters.SelectAsArray(Function(p) New AnonymousTypeKeyField(p.Name, isKey:=False)))
parameters.Add(New AnonymousTypeKeyField(AnonymousTypeDescriptor.GetReturnParameterName(Not method.IsSub), isKey:=False))
parameters.AddRange(method.Parameters.SelectAsArray(Function(p) New AnonymousTypeKeyField(p.Name)))
parameters.Add(New AnonymousTypeKeyField(AnonymousTypeDescriptor.GetReturnParameterName(Not method.IsSub)))
Return New AnonymousTypeKey(parameters.ToImmutableAndFree(), isDelegate:=True)
End Function
......
......@@ -125,7 +125,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Sub
Friend Overrides Function GetAnonymousTypeKey() As Microsoft.CodeAnalysis.Emit.AnonymousTypeKey
Dim parameters = TypeDescr.Parameters.SelectAsArray(Function(p) New Microsoft.CodeAnalysis.Emit.AnonymousTypeKeyField(p.Name, p.IsByRef))
Dim parameters = TypeDescr.Parameters.SelectAsArray(Function(p) New Microsoft.CodeAnalysis.Emit.AnonymousTypeKeyField(p.Name))
Return New Microsoft.CodeAnalysis.Emit.AnonymousTypeKey(parameters, isDelegate:=True)
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册