1

There is an old .ASPX page using "javascript" (JScript) as the page language.

And there is a C# method in a referenced assembly that should be invoked.

public void IX Locate(Type x)

Using C# this method can be invoked by supplying the corresponding Type object.

var o = locator.Locate(typeof(XImpl));

However, in JScript typeof operator always returns string instead of a desired Type object.

  • How is it possible to obtain the System.Type object in JScript (and invoke this method)?

I've been looking around the dated/introductory JScript documentation and have been unable to find a stuiable operator or method.


Edit: It is possible to use Type.GetType(name) or similar. However this requires manually resolving the type name instead of having the compiler do the work. This also requires having the assembly name.

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • 1
    JScript uses COM/Automation to communicate with the outside world. Automation only allows a few types (https://msdn.microsoft.com/en-us/library/cc237562.aspx) to pass, and System.Type is not one of them, you should convert your method so it takes a string as input that would represent the type's full name or assembly qualified full name, for example. – Simon Mourier Sep 08 '16 at 18:33
  • @SimonMourier Is there something different with .NET's JScript? The current code (of which there is "a lot") appears to be able to access "all" the types in our .NET assemblies, including those not explicitly marked for remoting. Is there a difference between being able to create .NET objects (and save them to local variables), invoke methods on said .NET objects, and pass objects through parameters? – user2864740 Sep 08 '16 at 18:38
  • .NET Jscript is 100% different, it's a real .NET language based on the CLR.. ASP.NET's JScript (or VBScript) is a COM object. You can only pass .NET object's marked with ComVisible attribute to COM JScript, it's not related to remoting at all. – Simon Mourier Sep 08 '16 at 18:52
  • Then I suppose this is ".NET JScript". I'll update the question for clarity, but it's the same question. – user2864740 Sep 08 '16 at 19:30
  • Unlike C#, JScript.NET's typeof returns a string, not a type per manual: https://msdn.microsoft.com/en-us/library/d70y8358.aspx – Simon Mourier Sep 08 '16 at 19:42
  • @SimonMourier Yes, and that is why I cannot use it. – user2864740 Sep 08 '16 at 19:45

0 Answers0