public static string FormatValue(Value val)
		{
			if (val == null) {
				return null;
			} if (val.IsNull) {
				return "null";
			} else if (val.Type.IsArray) {
				StringBuilder sb = new StringBuilder();
				sb.Append(val.Type.Name);
				sb.Append(" {");
				bool first = true;
				foreach(Value item in val.GetArrayElements()) {
					if (!first) sb.Append(", ");
					first = false;
					sb.Append(FormatValue(item));
				}
				sb.Append("}");
				return sb.ToString();
			} else if (val.Type.GetInterface(typeof(ICollection).FullName) != null) {
				StringBuilder sb = new StringBuilder();
				sb.Append(val.Type.Name);
				sb.Append(" {");
				val = val.GetPermanentReference();
				int count = (int)val.GetMemberValue("Count").PrimitiveValue;
				for(int i = 0; i < count; i++) {
					if (i > 0) sb.Append(", ");
					DebugPropertyInfo itemProperty = (DebugPropertyInfo)val.Type.GetProperty("Item");
					Value item = val.GetPropertyValue(itemProperty, Eval.CreateValue(val.AppDomain, i));
					sb.Append(FormatValue(item));
				}
				sb.Append("}");
				return sb.ToString();
			} else if (val.Type.FullName == typeof(char).FullName) {
				return "'" + val.PrimitiveValue.ToString() + "'";
			} else if (val.Type.FullName == typeof(string).FullName) {
				return "\"" + val.PrimitiveValue.ToString() + "\"";
			} else if (val.Type.IsPrimitive) {
				return val.PrimitiveValue.ToString();
			} else {
				return val.InvokeToString();
			}
		}
Esempio n. 2
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();
 }