2

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
pauldoo
  • 18,087
  • 20
  • 94
  • 116

2 Answers2

0

@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.

bugmagnet
  • 7,631
  • 8
  • 69
  • 131
-1
var WshShell = new ActiveXObject("WScript.Shell");

WshShell.Popup(Text, WaitSeconds, Title, Type);
Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
Anon
  • 1
  • How does this answer the OP's question? You should always provide some context or description with your answer to explain why this solution would work. – psubsee2003 Oct 26 '12 at 14:53