The JScript.NET typeof operator returns a String... are there any plans to
make an operator which returns a "System.Type"? It would be very useful,
for instance:
var list : ArrayList = new ArrayList();
...
return MyClass[](list.ToArray(typeof(MyClass)));
Currently, the only way I found to accomplish this is if I am able to make
an instance of MyClass to call the GetType() method:
var list : ArrayList = new ArrayList();
...
var temp : MyClass = new MyClass();
return MyClass[](list.ToArray(temp.GetType()));
But sometimes, this just isn't possible... i.e. the MyClass constructor does
something I do not want executed. There are ways to work around that even,
but then its just getting messy when all I want is a working typeof
operator.
> The JScript.NET typeof operator returns a String... are there any plans to
> make an operator which returns a "System.Type"? It would be very useful,
> for instance:
Why not just give it MyClass itself?
return MyClass[](list.ToArray(MyClass));
or, to make it a bit clearer:
var type : Type = MyClass
return MyClass[](list.ToArray(type));
In JScript, types are just values, like strings or numbers. You are probably
used to VB which only lets you use types in special contexts (and thus has
weird syntax for dealing with them). So no special operator is needed.
Both typeof (which is there for back-compat and is pretty useless) and
GetType() are for getting the type of an instance.
Peter

Signature
Please post questions to the newsgroup - everyone benefits.
This post is provided "AS IS" with no warranties, and confers no rights
Sample code subject to http://www.microsoft.com/info/cpyright.htm
Bore yourself to tears -- http://blogs.gotdotnet.com/ptorr