LOL I'd been contemplating a similar approach to a problem
I have with
each string having a corresponding description ;o) something
akin to a
Tooltip. And I'd like the idea of IFormattable.
For example I have a value (code) that requires a codestable
decode I
currently have two properties a) Value the raw value and b)
DisplayValue
the codestable decode - I also now need a tooltip
(description) for the
value - so me thought hang on IFormattable with D=Display,
R=Raw,
T=Tooltip..
Rob.
-----Original Message-----
From: Discussion of development on the .NET platform using
any managed
language [mailto OTNET-CL
R DISCUSS.DEVELOP.COM] On Behalf Of Ian
Griffiths
Sent: Tuesday, 1 August 2006 2:26 AM
To: DOTNET-CLR DISCUSS.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 <richard DOTNETCONSULT.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(r) 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
|