Emma,
I don't understand. The implementation of ToInt32 involves a cast to
IConvertible *internally* in order to do any useful work so the
method's parameter is too weakly typed *according to the
implementation*. Is this fact actually debatable?
I am not debating that. What I am debating is the suggestion that it was a
design mistake.
I don't understand the example you give: your calling To* methods
code. What does this example show? You know a priori the format in
which you intend to convert your data row column values because you're
calling particular methods and so you know those methods' signatures!
System.Data.DataRow.Item returns an Object.
Convert.ToInt32 accepts an Object.
The call Convert.ToInt32(dataRow.item(0)) would be calling
Convert.ToInt32(Object obj).
If Convert.ToInt32(Object obj) changed to be Convert.ToInt32(IConvertible
obj) which I agree is more semantically correct:
Convert.ToInt32(dataRow.item(0))
Would receive a compile error, unless I added the cast to IConvertible,
which would again be more semantically correct. However the amount of code I
need to write, just 'doubled', a wrapper function would be called for. I
would probably wrap the entire Convert class. Those wrappers are currently
embedded inside of Convert.ToInt32(Object obj).
The other options would be:
- To change DataRow.Item to be IConvertible instead of Object. Then what
about the case where DataRow is returning an IStream or an Image or some
other class where IConvertible does not make sense?
- To change DataRow to have type safe methods similar to DataReader, which
then looses the benefits of being an indexer.
I don't think this presents an argument against my conjecture.
I know. ;-) In that you are convinced that it needs to be IConvertible, from
a semantically point of view, I agree. However! I am trying to show that it
would cause extra coding when you attempt to apply the Convert class to
other classes in the Framework such as DataRow.
Hope this helps
Jay
emma middlebrook said:
"Jay B. Harlow [MVP - Outlook]" <
[email protected]> wrote in
message news: said:
Jon,
I suspect changing the signature to:
Would be a mistake because of the System.Data library.
As well as any other framework function that relies on IConvertible would
then need to encapsulate the cast. ArrayList.ToArray? ICollection.CopyTo?
Granted for functions inside the framework this is not as big deal, as for
functions that I may be using heavily.
Given an array of Objects, I can call Convert.To* on any item in the array.
Whereas if the signature was changed then I need to do the cast to
IConvertible. Seeing System.Data.DataRow has an array of Object for the
values (the index/item property), I can call Convert.To* as is, such as:
Dim dr As DataRow
w = Convert.ToInt32(dr.Item(0))
x = Convert.ToString(dr.Item(1))
y = Convert.ToBoolean(dr(2))
z = Convert.ToDouble(dr(3))
Without needing to have a bunch of casts to IConvertible in the above.
So in the long run, IConvertible value may appear to make sense, I think it
would be the 'design mistake'.
Jay
I don't understand. The implementation of ToInt32 involves a cast to
IConvertible *internally* in order to do any useful work so the
method's parameter is too weakly typed *according to the
implementation*. Is this fact actually debatable?
I don't understand the example you give: your calling To* methods
code. What does this example show? You know a priori the format in
which you intend to convert your data row column values because you're
calling particular methods and so you know those methods' signatures!
I don't think this presents an argument against my conjecture.
Hoping that you or someone can explain a little further for me.
Thanks
Emma Middlebrook
(e-mail address removed)