List Info

Thread: object.ToString() or TypeConverter




object.ToString() or TypeConverter
user name
2006-07-31 12:31:50
Richard Blewett <richardDOTNETCONSULT.CO.UK>
wrote:

> Ah ok - I see what you're getting at.
> 
> But surely the ToolTip would be served (ignoring the
built in support) by a
> ToolTip property

Let's not forget that there's built-in support for exactly
specifying
the kind of ToString() via a passed format specification
(IFormattable),
which can also be used by string.Format etc.

-- Barry

-- 
http://barrkel.blogspot.
com/

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

object.ToString() or TypeConverter
user name
2006-07-31 16:26:28
True, but I think that using this to select between a number
of strings
that serves a completely different purpose would be a case
of stretching
things a little.

When you use IFormattable on any of the built-in types,
you're not
actually changing the data that is shown. You're just
controlling how
that data is shown. For numbers you can select things like
the
precision, the style and so on, but it's always the same
number.

It's a clever hack to use IFormattable as a solution to
this problem,
but I think it's ultimately rather confusing. It's very
non-discoverable, and also really rather different from how
IFormattable
is normally used. Moreover, it's at odds with what the
documentation for
IFormattable.ToString says. (Or at least, I don't think
that "the value
of" is synonymous with "the value of one of the
properties of"...)

So on the 'principle of least astonishment' basis, I'd
avoid using
IFormattable as a means of selecting between different data
items to be
returned from ToString.

If an object has a number of different pieces of information
associated
with it, then the most obvious way to expose those is
through a number
of properties. After all, I think the following is pretty
readable:

  string msg = myObj.ToolTipMessage;

whereas this is a lot less clear:

  string msg = myObj.ToString("T");

or

  string msg = string.Format("{0:T}", myObj);



-- 
Ian Griffiths
http://www.int
eract-sw.co.uk/iangblog/ 

> -----Original Message-----
> From: Barry Kelly
> 
> Richard Blewett <richardDOTNETCONSULT.CO.UK>
wrote:
> 
> > Ah ok - I see what you're getting at.
> >
> > But surely the ToolTip would be served (ignoring
the built in
support)
> by a
> > ToolTip property
> 
> Let's not forget that there's built-in support for
exactly specifying
> the kind of ToString() via a passed format
specification
(IFormattable),
> which can also be used by string.Format etc.

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

object.ToString() or TypeConverter
user name
2006-07-31 17:15:24
Ian Griffiths <ianINTERACT-SW.CO.UK> wrote:

> True, but I think that using this to select between a
number of strings
> that serves a completely different purpose would be a
case of stretching
> things a little.

I'm sorry, I didn't quote enough context. I pointed out
the
configurability of ToString(), but the reference to tooltips
was a proxy
for "detailed information about the object", as
opposed to a 'T for
tooltip' formatting specifier. Instead, one would create a
specifier in
the spirit of the precision specifier for floats. The
context:

John Brett wrote:
> However, if I also want to display tooltips for each
item, giving
> much more detailed information about the object
(perhaps an
> indicator of internal state, as well as just, say,
name), then I
> need another way of getting that information.

Sorry for the confusion.

-- Barry

-- 
http://barrkel.blogspot.
com/

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

object.ToString() or TypeConverter
user name
2006-08-02 21:08:24
Ian,

Interestingly that calling ToString() on a DateTime of
12/12/2006 can yield
different representations i.e. it can display 12, December
2006 I see this
as a kind of code/decode the only thing being people expect
December as it's
part of everyday life. Values within applications also being
code/decode
e.g., 145 can be 'Business User' 125 'Home User' would
this be fair use of
ToString("L") L=LongDescription?

Rob.

-----Original Message-----
From: Discussion of development on the .NET platform using
any managed
language [mailtoOTNET-CL
RDISCUSS.DEVELOP.COM] On Behalf Of Ian Griffiths
Sent: Tuesday, August 01, 2006 2:26 AM
To: DOTNET-CLRDISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-CLR] object.ToString() or TypeConverter

True, but I think that using this to select between a number
of strings
that serves a completely different purpose would be a case
of stretching
things a little.

When you use IFormattable on any of the built-in types,
you're not
actually changing the data that is shown. You're just
controlling how
that data is shown. For numbers you can select things like
the
precision, the style and so on, but it's always the same
number.

It's a clever hack to use IFormattable as a solution to
this problem,
but I think it's ultimately rather confusing. It's very
non-discoverable, and also really rather different from how
IFormattable
is normally used. Moreover, it's at odds with what the
documentation for
IFormattable.ToString says. (Or at least, I don't think
that "the value
of" is synonymous with "the value of one of the
properties of"...)

So on the 'principle of least astonishment' basis, I'd
avoid using
IFormattable as a means of selecting between different data
items to be
returned from ToString.

If an object has a number of different pieces of information
associated
with it, then the most obvious way to expose those is
through a number
of properties. After all, I think the following is pretty
readable:

  string msg = myObj.ToolTipMessage;

whereas this is a lot less clear:

  string msg = myObj.ToString("T");

or

  string msg = string.Format("{0:T}", myObj);



--
Ian Griffiths
http://www.int
eract-sw.co.uk/iangblog/

> -----Original Message-----
> From: Barry Kelly
>
> Richard Blewett <richardDOTNETCONSULT.CO.UK>
wrote:
>
> > Ah ok - I see what you're getting at.
> >
> > But surely the ToolTip would be served (ignoring
the built in
support)
> by a
> > ToolTip property
>
> Let's not forget that there's built-in support for
exactly specifying
> the kind of ToString() via a passed format
specification
(IFormattable),
> which can also be used by string.Format etc.

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )