Re: Accessing value type static members via instance?
From: Ray Manning (reply_at_newsgroup.please)
Date: 12/10/04
- Next message: stewartmclean_at_supanet.com: "Re: SqlParameters anomoly"
- Previous message: Bruce Wood: "Re: Accessing value type static members via instance?"
- In reply to: Bruce Wood: "Re: Accessing value type static members via instance?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 9 Dec 2004 16:01:00 -0800
I don't think what I'm doing or how far away it is even entered my mind.
What did enter my mind (as I typed int.MaxValue) was that perhaps the type
of x would change in width sometime in the future for whatever reason
(performance, etc.) and that statement would still compile fine but not work
as expected and I was looking for a way to avoid that possibility.
Reflection isn't the way to do this and I wouldn't use it in this case
because it'll unnecessarily bloat the code. However, since the Type of X is
a ValueType and is known at compile time, I don't understand why the
compiler would not allow x.StaticMethod. If X was a reference type,
complexity would increase by orders of magnitude likely resulting in
ambiguity (or reflection code) somewhere along the line so I'm not
suggesting that should be allowed, besides, with a reference type you would
use a virtual method MaxValue and if the type changed, the MaxValue method
would change along with it.
It just seemed to me that there was a possiblity I was missing something I
should be taking adavantage of in the language. It would appear not.
- Ray
"Bruce Wood" <brucewood@canada.com> wrote in message
news:1102631423.200656.268160@z14g2000cwz.googlegroups.com...
> You certainly don't need generics.
>
> You certainly do need reflection.
>
> if (x == (int)x.GetType().GetField("MaxValue").GetValue(null))
> {
> ...
> }
>
> However, I have to ask what you are doing that you can't just use
> "int.MaxValue"? You say that you're concerned about the type of x
> changing, but how far away is the code from the declaration? It looks
> to me, with what little information I have at my disposal, that using
> reflection as I showed above is massive overengineering for change
- Next message: stewartmclean_at_supanet.com: "Re: SqlParameters anomoly"
- Previous message: Bruce Wood: "Re: Accessing value type static members via instance?"
- In reply to: Bruce Wood: "Re: Accessing value type static members via instance?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|