Example #1
0
 /// <summary>
 /// Возвращает текстовое представление для значения val
 /// </summary>
 public string MakeValueView(Value val)
 {
     bool by_ref = false;
     if ((val.Type.IsByRef() && !val.Type.IsPrimitive))
     {
         by_ref = true;
         val = val.Dereference;
     }
     int v = 0;
     NamedValue nv = GetNullBasedArray(val);//mozhet eto massiv
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     if (nv != null)//staticheskij massiv
     {
         sb.Append('(');
         NamedValueCollection nvc = nv.GetArrayElements();
         for (int i = 0; i < nvc.Count; i++)
         {
             if (i > 10)
             {
                 sb.Append("...");
                 break;
             }
             sb.Append(MakeValueView(nvc[i]));
             if (i < nvc.Count - 1) sb.Append(',');
         }
         sb.Append(')');
         //sb.AppendLine();
         //sb.Remove(
     }
     else if (val.IsPrimitive)
     {
         if (val.Type.ManagedType == typeof(string) || val.Type.ManagedType == typeof(char))
             sb.Append("'" + val.AsString + "'");
         else
             sb.Append(val.AsString);
     }
     else if (val.IsNull)
     {
         sb.Append("nil");
     }
     else if (DebugUtils.IsEnum(val, out v))
     {
         sb.Append(ValueItem.MakeEnumText(val));
     }
     else if (val.Type.IsValueType && val.Type.GetMembers().Count <= 7)
     {
         sb.Append('{');
         NamedValueCollection nvc = val.GetMembers();
         for (int i = 0; i < nvc.Count; i++)
         {
             sb.Append(nvc[i].Name + ": " + MakeValueView(nvc[i]));
             if (i < nvc.Count - 1) sb.Append("; ");
         }
         sb.Append('}');
     }
     else if (val.IsArray)//dinamicheskij massiv
     {
         NamedValueCollection nvc = val.GetArrayElements();
         sb.Append('(');
         for (int i = 0; i < nvc.Count; i++)
         {
             if (i > 10)
             {
                 sb.Append("...");
                 break;
             }
             sb.Append(MakeValueView(nvc[i]));
             if (i < nvc.Count - 1) sb.Append(',');
         }
         sb.Append(')');
         //sb.AppendLine();
     }
     else if (val.IsObject)
     {
         if (val.Type.FullName == "PABCSystem.TypedSet")
             sb.Append((val.Type.GetMember("ToString", BindingFlags.All)[0] as MethodInfo).Invoke(val, new Value[0] { }).AsString);
         else
             if (!val.Type.IsPrimitive)
             {
                 if (DebugUtils.CheckForCollection(val.Type))
                     return DebugUtils.MakeViewForCollection(val);//esli eto kollekcija, to vyvodim ee po osobomu 
                 bool is_failed = false;
                 string s = ExpressionEvaluator.GetToString(val, out is_failed);
                 if (s != null) return s;
                 else return val.AsString;
             }
             else
                 return val.AsString;
     }
     else return val.AsString;
     return sb.ToString();
 }