Hum, I don't know how generalized that scenario is, but it sure does not look clean to me and if I really want to do that, I would use the more explicit call
TryParse<object>(input, out value) to make clear my intention. Anyway, I can live with that, I will just be more careful to watch for yet another trap (YAT). Sébastien On 4/11/08, Mark Hurd <[EMAIL PROTECTED]> wrote: > On 12/04/2008, Sébastien Lorion <[EMAIL PROTECTED]> wrote: > > Well, in my code I have another method similar to: > > > > void DoStuff(Type type, string input) > > { > > object value; > > if (TryParse(input, out value)) > > { > > // ... > > } > > } > > > > I made a mistake and forgot to pass "type" to TryParse. I discovered > > the bug only at runtime when testing my code. I can understand the > > compiler behavior, but it is not what I expect since I think in most > > case, the programmer did not intend to do that. A warning would be > > nice here IMO. > > > > Sébastien > > > I assume the warning you're looking for is something like "Generic > type inferred as Object", which would be the deliberate case for too > many situations to be a warning. (Remember that in most cases warnings > are seen as "show stoppers" -- the only valid final build is one > without any warnings.) > > However, if you want it to be a warning or invalid for your code, add > an overload: > > [Obsolete("Is this what you really meant?", false)] > bool TryParse(string Input, out object Value) > > And when the overload resolution matches that signature, you'll get > the Obsolete warning (or error if you pass True in the > ObsoleteAttribute reference). > > Regards, > Mark Hurd, B.Sc.(Ma.)(Hons.) > > P.S. I've hand crafted the C# code above from this hand crafted VB.NET: > > <Obsolete("Is this what you really meant?", False)> _ > Function TryParse(ByVal Input As String, <Out()> ByRef Value As > Object> As Boolean > > =================================== > This list is hosted by DevelopMentor(R) http://www.develop.com > > > View archives and manage your subscription(s) at http://discuss.develop.com > -- Sébastien www.sebastienlorion.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com