Exemplo n.º 1
0
        public static string __repr__(CodeContext /*!*/ context, [NotNull] Array /*!*/ self)
        {
            List <object> infinite = PythonOps.GetAndCheckInfinite(self);

            if (infinite == null)
            {
                return("...");
            }

            int index = infinite.Count;

            infinite.Add(self);
            try {
                StringBuilder ret = new StringBuilder();
                if (self.Rank == 1)
                {
                    // single dimensional Array's have a valid display
                    ret.Append("Array[");
                    Type elemType = self.GetType().GetElementType();
                    ret.Append(DynamicHelpers.GetPythonTypeFromType(elemType).Name);
                    ret.Append("]");
                    ret.Append("((");
                    for (int i = 0; i < self.Length; i++)
                    {
                        if (i > 0)
                        {
                            ret.Append(", ");
                        }
                        ret.Append(PythonOps.Repr(context, self.GetValue(i + self.GetLowerBound(0))));
                    }
                    ret.Append("))");
                }
                else
                {
                    // multi dimensional arrays require multiple statements to construct so we just
                    // give enough info to identify the object and its type.
                    ret.Append("<");
                    ret.Append(self.Rank);
                    ret.Append(" dimensional Array[");
                    Type elemType = self.GetType().GetElementType();
                    ret.Append(DynamicHelpers.GetPythonTypeFromType(elemType).Name);
                    ret.Append("] at ");
                    ret.Append(PythonOps.HexId(self));
                    ret.Append(">");
                }
                return(ret.ToString());
            } finally {
                System.Diagnostics.Debug.Assert(index == infinite.Count - 1);
                infinite.RemoveAt(index);
            }
        }
Exemplo n.º 2
0
        public static string __repr__(CodeContext /*!*/ context, Dictionary <K, V> self)
        {
            List <object> infinite = PythonOps.GetAndCheckInfinite(self);

            if (infinite == null)
            {
                return("{...}");
            }

            int index = infinite.Count;

            infinite.Add(self);
            try {
                StringBuilder res = new StringBuilder();
                res.Append("Dictionary[");
                res.Append(DynamicHelpers.GetPythonTypeFromType(typeof(K)).Name);
                res.Append(", ");
                res.Append(DynamicHelpers.GetPythonTypeFromType(typeof(V)).Name);
                res.Append("](");
                if (self.Count > 0)
                {
                    res.Append("{");
                    string comma = "";
                    foreach (KeyValuePair <K, V> obj in self)
                    {
                        res.Append(comma);
                        res.Append(PythonOps.Repr(context, obj.Key));
                        res.Append(" : ");
                        res.Append(PythonOps.Repr(context, obj.Value));
                        comma = ", ";
                    }
                    res.Append("}");
                }

                res.Append(")");
                return(res.ToString());
            } finally {
                Debug.Assert(index == infinite.Count - 1);
                infinite.RemoveAt(index);
            }
        }
Exemplo n.º 3
0
        public static string __repr__(CodeContext /*!*/ context, List <T> self)
        {
            List <object> infinite = PythonOps.GetAndCheckInfinite(self);

            if (infinite == null)
            {
                return("[...]");
            }

            int index = infinite.Count;

            infinite.Add(self);
            try {
                StringBuilder res = new StringBuilder();
                res.Append("List[");
                res.Append(DynamicHelpers.GetPythonTypeFromType(typeof(T)).Name);
                res.Append("](");
                if (self.Count > 0)
                {
                    res.Append("[");
                    string comma = "";
                    foreach (T obj in self)
                    {
                        res.Append(comma);
                        res.Append(PythonOps.Repr(context, obj));
                        comma = ", ";
                    }
                    res.Append("]");
                }

                res.Append(")");
                return(res.ToString());
            } finally {
                System.Diagnostics.Debug.Assert(index == infinite.Count - 1);
                infinite.RemoveAt(index);
            }
        }