Ejemplo n.º 1
0
 protected virtual T VisitPyDictionaryCreateExpression(PyDictionaryCreateExpression node)
 {
     if (ThrowNotImplementedException)
     {
         throw new NotImplementedException(string.Format("Method {0} is not supported in class {1}", "VisitPyDictionaryCreateExpression", this.GetType().FullName));
     }
     return(default(T));
 }
Ejemplo n.º 2
0
        private static object __Translate_CallConstructor(CallConstructor x, IExternalTranslationContext ctx)
        {
            if (x.Arguments.Length != 0)
            {
                throw new NotSupportedException();
            }
            if (x.Initializers.Length == 0)
            {
                return(new PyMethodCallExpression("dict"));
            }

            var d = new PyDictionaryCreateExpression();

            foreach (var i in x.Initializers)
            {
                if (i is CsharpAssignExpression ae)
                {
                    if (ae.Left is FunctionArguments_PseudoValue pv)
                    {
                        if (pv.Arguments.Length != 1)
                        {
                            throw new NotSupportedException("Key is multivalue");
                        }
                        var key   = ctx.TranslateValue(pv.Arguments[0].MyValue);
                        var value = ctx.TranslateValue(ae.Right);
                        var item  = new KeyValuePair <IPyValue, IPyValue>(key, value);
                        d.Initializers.Add(item);
                    }
                    else
                    {
                        throw new NotSupportedException(ae.Left?.GetType().ToString());
                    }
                }
                else
                {
                    throw new NotSupportedException(i?.GetType().ToString());
                }
            }

            return(d);
        }