public override void ExitMapType(GoParser.MapTypeContext context) { string type = context.GetText(); Types.TryGetValue(context.type_(), out TypeInfo keyTypeInfo); if (keyTypeInfo is null) { return; // throw new InvalidOperationException("Map key type undefined."); } Types.TryGetValue(context.elementType().type_(), out TypeInfo elementTypeInfo); if (elementTypeInfo is null) { return; // throw new InvalidOperationException("Map element type undefined."); } Types[context.Parent.Parent] = new MapTypeInfo { Name = type, TypeName = $"map<{keyTypeInfo.TypeName}, {elementTypeInfo.TypeName}>", FullTypeName = $"go.map<{keyTypeInfo.FullTypeName}, {elementTypeInfo.FullTypeName}>", ElementTypeInfo = elementTypeInfo, KeyTypeInfo = keyTypeInfo, TypeClass = TypeClass.Map }; }
public override void ExitMapType(GoParser.MapTypeContext context) { string type = context.GetText(); Types.TryGetValue(context.type_(), out TypeInfo keyTypeInfo); if (keyTypeInfo == null) { return; // throw new InvalidOperationException("Map key type undefined."); } Types.TryGetValue(context.elementType().type_(), out TypeInfo elementTypeInfo); if (elementTypeInfo == null) { return; // throw new InvalidOperationException("Map element type undefined."); } RequiredUsings.Add("System.Collections.Generic"); Types[context.Parent.Parent] = new MapTypeInfo { Name = type, TypeName = $"Dictionary<{keyTypeInfo.TypeName}, {elementTypeInfo.TypeName}>", FullTypeName = $"System.Collections.Generic.Dictionary<{keyTypeInfo.FullTypeName}, {elementTypeInfo.FullTypeName}>", ElementTypeInfo = elementTypeInfo, KeyTypeInfo = keyTypeInfo, TypeClass = TypeClass.Map }; }