Re: current type in static methods

From: Daniel O'Connell [C# MVP] (onyxkirx_at_--NOSPAM--comcast.net)
Date: 03/24/04


Date: Wed, 24 Mar 2004 08:19:10 -0600


"codymanix" <no_spam_deutronium@gmx.net> wrote in message
news:etVy8OYEEHA.3384@TK2MSFTNGP12.phx.gbl...
>> > I know of a scripting language for the java platform named "Groovy"
> which
>> > understands the this keyword in the context of a static method
>> > as a reference to the current class which is similar to my proposal.
>> > So in Groovy the following would be valid:
>> >
>> > class A
>> > {
>> > static int s=1234;
>> >
>> > static int getS()
>> > {
>> > return this.s; // note usage of this in static mehtod
>> > }
>> > }
>> >
>> >
>> > --
>> > cody
>>
>> And what would you consider this to mean?
>>
>> class A
>> {
>> static int s=1234;
>>
>> int getS()
>> {
>> return class.s; //note the use of class here
>> }
>> }
>>
>> My point is more in should class exist within instance methods, or should
> it
>> be valid only in static.
>
>
> if a keyword "class" could be used to identify the current class, it
> should
> be allowed in static *and* instance methods,
> because using GetType() or class has a different meaning, so using class
> in
> instance method is useful too:
>
> class A{
> public A()
> {
> Console.WriteLine(
> System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);Console.Write
> Line( this.GetType());
> }
> }
>
> class B:A{}
>
> new B();
>
> Outputs A,B.
>
> GetType() denotes the dynamic type while class (which is a short form for
> MethodBase.GetCurrentMethod().DeclaringType) denotes the declaring class.
>

Which misses my point entirely. I was suggesting the usage of class as a
pointer similar to this, instead of as a type explictly, typeof(class) may
or may not make sense in this particular situation.

Personally, typeof(class) is far to limited to be a feature on its own. It
introduces a use of class that is inconsistent with the rest of hte
langauge.
> --
> cody
>
> Freeware Tools, Games and Humour
> http://www.deutronium.de.vu || http://www.deutronium.tk
>
>