Browse Source

Add maxLength parameter to Value.AsString() method.

pull/14/head
Daniel Grunwald 15 years ago
parent
commit
6dfa03cd02
  1. 4
      src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml.cs
  2. 2
      src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs
  3. 2
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/ExpressionNode.cs
  4. 4
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs
  5. 4
      src/AddIns/Debugger/Debugger.Core/Exception.cs
  6. 2
      src/AddIns/Debugger/Debugger.Core/Thread.cs
  7. 33
      src/AddIns/Debugger/Debugger.Core/Value.cs

4
src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml.cs

@ -186,9 +186,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
} }
if (showArgumentValues) { if (showArgumentValues) {
try { try {
argValue = frame.GetArgumentValue(i).AsString; argValue = frame.GetArgumentValue(i).AsString(100);
if (argValue != null && argValue.Length > 100)
argValue = argValue.Substring(0, 100) + "...";
} catch { } } catch { }
} }
if (parameterName != null && argValue != null) { if (parameterName != null && argValue != null) {

2
src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs

@ -382,7 +382,7 @@ namespace ICSharpCode.SharpDevelop.Services
try { try {
Value val = GetValueFromName(variableName); Value val = GetValueFromName(variableName);
if (val == null) return null; if (val == null) return null;
return val.AsString; return val.AsString();
} catch (GetValueException) { } catch (GetValueException) {
return null; return null;
} }

2
src/AddIns/Debugger/Debugger.AddIn/TreeModel/ExpressionNode.cs

@ -195,7 +195,7 @@ namespace Debugger.AddIn.TreeModel
return; return;
} }
} else { } else {
fullText = val.AsString; fullText = val.AsString();
} }
this.Text = (fullText.Length > 256) ? fullText.Substring(0, 256) + "..." : fullText; this.Text = (fullText.Length > 256) ? fullText.Substring(0, 256) + "..." : fullText;

4
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Utils/DebuggerHelpers.cs

@ -88,11 +88,11 @@ namespace Debugger.AddIn.Visualizers.Utils
// value.InvokeMethod is nice for instance methods. // value.InvokeMethod is nice for instance methods.
// what about MethodInfo.Invoke() ? // what about MethodInfo.Invoke() ?
// also, there could be an overload that takes 1 parameter instead of array // also, there could be an overload that takes 1 parameter instead of array
string defaultHashCode = Eval.InvokeMethod(DebuggerHelpers.hashCodeMethod, null, new Value[]{value}).AsString; Value defaultHashCode = Eval.InvokeMethod(DebuggerHelpers.hashCodeMethod, null, new Value[]{value});
//MethodInfo method = value.Type.GetMember("GetHashCode", BindingFlags.Method | BindingFlags.IncludeSuperType) as MethodInfo; //MethodInfo method = value.Type.GetMember("GetHashCode", BindingFlags.Method | BindingFlags.IncludeSuperType) as MethodInfo;
//string hashCode = value.InvokeMethod(method, null).AsString; //string hashCode = value.InvokeMethod(method, null).AsString;
return int.Parse(defaultHashCode); return (int)defaultHashCode.PrimitiveValue;
} }
public static Value EvalPermanentReference(this Expression expr) public static Value EvalPermanentReference(this Expression expr)

4
src/AddIns/Debugger/Debugger.Core/Exception.cs

@ -33,7 +33,7 @@ namespace Debugger
public string Message { public string Message {
get { get {
Value message = exception.GetMemberValue("_message"); Value message = exception.GetMemberValue("_message");
return message.IsNull ? string.Empty : message.AsString; return message.IsNull ? string.Empty : message.AsString();
} }
} }
@ -86,7 +86,7 @@ namespace Debugger
// Note that evaluation is not possible after a stackoverflow exception // Note that evaluation is not possible after a stackoverflow exception
Value stackTrace = exception.GetMemberValue("StackTrace"); Value stackTrace = exception.GetMemberValue("StackTrace");
if (!stackTrace.IsNull) { if (!stackTrace.IsNull) {
sb.Append(stackTrace.AsString); sb.Append(stackTrace.AsString());
sb.AppendLine(); sb.AppendLine();
} }
return sb.ToString(); return sb.ToString();

2
src/AddIns/Debugger/Debugger.Core/Thread.cs

@ -156,7 +156,7 @@ namespace Debugger
if (runtimeValue.IsNull) return string.Empty; if (runtimeValue.IsNull) return string.Empty;
Value runtimeName = runtimeValue.GetMemberValue("m_Name"); Value runtimeName = runtimeValue.GetMemberValue("m_Name");
if (runtimeName.IsNull) return string.Empty; if (runtimeName.IsNull) return string.Empty;
return runtimeName.AsString.ToString(); return runtimeName.AsString(100);
} }
} }

33
src/AddIns/Debugger/Debugger.Core/Value.cs

@ -149,12 +149,23 @@ namespace Debugger
} }
/// <summary> Gets a string representation of the value </summary> /// <summary> Gets a string representation of the value </summary>
public string AsString { /// <param name="maxLength">
get { /// The maximum length of the result string.
/// </param>
public string AsString(int maxLength = int.MaxValue)
{
if (this.IsNull) return "null"; if (this.IsNull) return "null";
if (this.Type.IsPrimitive) return PrimitiveValue.ToString(); if (this.Type.IsPrimitive || this.Type.FullName == typeof(string).FullName) {
if (this.Type.FullName == typeof(string).FullName) return PrimitiveValue.ToString(); string text = PrimitiveValue.ToString();
return "{" + this.Type.FullName + "}"; if (text != null && text.Length > maxLength)
text = text.Substring(0, Math.Max(0, maxLength - 3)) + "...";
return text;
} else {
string name = this.Type.FullName;
if (name != null && name.Length > maxLength)
return "{" + name.Substring(0, Math.Max(0, maxLength - 5)) + "...}";
else
return "{" + name + "}";
} }
} }
@ -600,14 +611,14 @@ namespace Debugger
} }
/// <summary> Invoke the ToString() method </summary> /// <summary> Invoke the ToString() method </summary>
public string InvokeToString() public string InvokeToString(int maxLength = int.MaxValue)
{ {
if (this.Type.IsPrimitive) return AsString; if (this.Type.IsPrimitive) return AsString(maxLength);
if (this.Type.FullName == typeof(string).FullName) return AsString; if (this.Type.FullName == typeof(string).FullName) return AsString(maxLength);
if (this.Type.IsPointer) return "0x" + this.PointerAddress.ToString("X"); if (this.Type.IsPointer) return "0x" + this.PointerAddress.ToString("X");
// if (!IsObject) // Can invoke on primitives // if (!IsObject) // Can invoke on primitives
DebugMethodInfo methodInfo = (DebugMethodInfo)this.AppDomain.ObjectType.GetMethod("ToString", new DebugType[] {}); DebugMethodInfo methodInfo = (DebugMethodInfo)this.AppDomain.ObjectType.GetMethod("ToString", new DebugType[] {});
return Eval.InvokeMethod(methodInfo, this, new Value[] {}).AsString; return Eval.InvokeMethod(methodInfo, this, new Value[] {}).AsString(maxLength);
} }
#region Convenience overload methods #region Convenience overload methods
@ -636,9 +647,7 @@ namespace Debugger
public override string ToString() public override string ToString()
{ {
return this.AsString; return this.AsString();
} }
} }
} }

Loading…
Cancel
Save