Home All Groups Group Topic Archive Search About

Debugger and watch issue with strings and own defined type

Author
25 Mar 2005 2:09 AM
Girish
Ok, starting from the basics. Reference types and value types are all
objects underneath.

So, a String is an object as well.

Now, when when we are debugging and we examine the contents of a String
object - the debugger actually shows the value of containing string object
when you keep a watch on the instance variable.

But when I create my OWN type which holds a string inside - and get this
1) Have an implicit conversion from string -> object
2) Have an implicit conversion from object -> string AND
3) Have the ToString() method overridden

The debugger still shows me the value of my object as the fully qualified
class name!

How is the String class object built so that the debugger knows to show the
internal string/byte array, whatever as the value and not the fully
qualified name of the class which should be "System.String" i think.

The code for my class is below.

Thanks,
Girish

StringWrapper
---------------

using System;
namespace test1 {
public class StringWrapper {
  private String _val;

  public String val {
   get { return _val; }
  }

  public StringWrapper(String val) {
   this._val = val;
  }

  public override string ToString() {
   return val;
  }

  static public implicit operator StringWrapper(String val)
  {
   val += " (im changed)";
   return new StringWrapper(val);
  }

  static public implicit operator string(StringWrapper val) {
   return val.val;
  }
}
}

Author
25 Mar 2005 10:20 AM
Mattias Sjögren
>How is the String class object built so that the debugger knows to show the
>internal string/byte array, whatever as the value and not the fully
>qualified name of the class which should be "System.String" i think.

The debugger probably has built in special handling of strings.

But you should check out the file Visual
Studio\Common7\Packages\Debugger\mcee_cs.dat. In it you can modify how
a certain type shows up in the debugger windows.



Mattias

--
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
25 Mar 2005 10:57 PM
Alvin Bruney [ASP.NET MVP]
Mattias,
can you use that technique to force the debugger tooltip to display
stringbuilder variables? I really need the ability to hover over a
stringbuilder object and find its values.

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
_________________________


Show quote
"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
news:uOBdvQSMFHA.732@TK2MSFTNGP12.phx.gbl...
> >How is the String class object built so that the debugger knows to show
> >the
>>internal string/byte array, whatever as the value and not the fully
>>qualified name of the class which should be "System.String" i think.
>
> The debugger probably has built in special handling of strings.
>
> But you should check out the file Visual
> Studio\Common7\Packages\Debugger\mcee_cs.dat. In it you can modify how
> a certain type shows up in the debugger windows.
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
Author
29 Mar 2005 10:13 AM
Mattias Sjögren
>can you use that technique to force the debugger tooltip to display
>stringbuilder variables? I really need the ability to hover over a
>stringbuilder object and find its values.

I've never tried so I don't know for sure, but I don't see why not.
Try it!



Mattias

--
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

AddThis Social Bookmark Button