public DataType VisitDictInitializer(DictInitializer d) { DataType keyType = ResolveUnion(d.KeyValues.Select(kv => kv.Key)); DataType valType = ResolveUnion(d.KeyValues.Select(kv => kv.Value)); return(analyzer.TypeFactory.CreateDict(keyType, valType)); }
public CodeExpression VisitDictInitializer(DictInitializer s) { var items = s.KeyValues.Select(kv => new CodeCollectionInitializer( kv.Key.Accept(this), kv.Value.Accept(this))); m.EnsureImport("System.Collections.Generic"); var init = new CodeObjectCreateExpression { Type = new CodeTypeReference("Dictionary") { TypeArguments = { m.TypeRef("object"), m.TypeRef("object"), } }, Initializer = new CodeCollectionInitializer { Values = items.ToArray() } }; return(init); }
public CodeExpression VisitDictInitializer(DictInitializer s) { if (s.KeyValues.All(kv => kv.Key != null)) { var items = s.KeyValues.Select(kv => new CodeCollectionInitializer( kv.Key.Accept(this), kv.Value.Accept(this))); m.EnsureImport("System.Collections.Generic"); var init = new CodeObjectCreateExpression { Type = m.TypeRef("Dictionary", "object", "object"), Initializer = new CodeCollectionInitializer { Values = items.ToArray() } }; return(init); } else { m.EnsureImport("pytocs.runtime"); // There was a dictionary unpacking present. var items = s.KeyValues.Select(kv => { var v = kv.Value.Accept(this); if (kv.Key != null) { var k = kv.Key.Accept(this); return(m.ValueTuple(k, v)); } else { return(v); } }); var unpack = m.MethodRef(m.TypeRefExpr("DictionaryUtils"), "Unpack"); unpack.TypeReferences.Add(m.TypeRef(typeof(string))); unpack.TypeReferences.Add(m.TypeRef(typeof(object))); return(m.Appl(unpack, items.ToArray())); } }
public void VisitDictInitializer(DictInitializer di) { throw new NotImplementedException(); }
public void VisitDictInitializer(DictInitializer di) { throw new NotImplementedException(); }