Can I use .NET classes from JScript.NET without import statement?

509 views Asked by At

How can I use classes without having to import the namespace in JScript.NET?

E.g. I want to be able to write System.Windows.Forms.MessageBox.Show("Ping"); instead of:

import System.Windows.Forms;
MessageBox.Show("Ping");

Is there a way to do this in JScript.NET?

2

There are 2 answers

1
Anon On
var WshShell = new ActiveXObject("WScript.Shell");

WshShell.Popup(Text, WaitSeconds, Title, Type);
0
bugmagnet On

@Anon suggested using WScript.Shell instead of System.Windows.Forms.MessageBox.Show. I think what s/he was trying to communicate is that, if you are after a one-liner, you're not going to get it using assembly notation. However, if you're willing to hook into ActiveX, then a one-liner equivalent is as follows:

(new ActiveXObject("WScript.Shell")).Popup('Ping');

BTW, I have been fiddling for a while, trying to get a pure .NET solution figured out, but so far it has eluded me.

And, if this page about ASP.NET is anything to go by, it should probably be assumed that JScript.NET does NOT automatically import a large swathe of namespaces.