Re: Accessing value type static members via instance?

From: Ray Manning (reply_at_newsgroup.please)
Date: 12/10/04


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



Relevant Pages

  • Re: Entropy sources under WinXP
    ... imply beneath the rebellion, ... consulting in response to obliged, in support of misleading, ... Who does Sayed oppose so for instance, ...
    (sci.crypt)
  • Re: I want to make a C# library of some classes
    ... compile the BaseParser with the generated library - seems too simple for me ... so the second thing that comes into my mind is to let them ... makes our class work to make their class work, ... would actually compile in C as well as C++. ...
    (microsoft.public.dotnet.languages.csharp)
  • Have A Nice Sunday! :-)
    ... That's what I had in mind when I said I do ... India Arie - The Truth Lyrics ... way that he makes me feelAnd if I am a reflection if him ...
    (soc.culture.vietnamese)
  • Re: Handling Bugs
    ... Keep in mind that while you can compile your code before you distribute it ... Keep in mind that any un- handled error in the runtime is a much ... but in the runtime those un-handled errors does not ... So, the issue of making sure one's code having compile errors is important, ...
    (microsoft.public.access.formscoding)
  • Re: How to RUN C by Microsoft Visual Studio =?UTF-8?B?6YG46aCF?=
    ... Does somebody know how to compile, ... Well, your program is started, it creates a console window, does whatever it ... Set a breakpoint near the end (F9 toggles breakpoints for a line). ... Wait for the user to press a key (getc comes to mind). ...
    (microsoft.public.vc.language)