Start a new topic

Javascript Binding Class with typeof(T) Error


I have a very simple function to get class full name


string name = GetClassName<System.Angular.Scope>();
System.Console.WriteLine("Class Name: {0}", name);

public string GetClassName<T>() where T : class
Type classType = typeof(T);
return classType.FullName;

    [Js(Extern = true)]
    public class Scope : RootScopeService {...}


When run get error: System.Exception: Scope is not defined

Scope class is there its just marked [Extern = true]

Now if i make just a regular class or take off Extern = true ...

the typeof(T) works just fine... Just not with Js Binding classes...

I need to get the type of a <T> including Javascript binding classes

typeof(Namespace.Class) will look for such class/function in JavaScript, under it's full qualified name including namespace.

To resolve this first ensure that JS external class Scope is actually defined under such namespace on JS side, or alternatively use [Js(Name = "Scope_Name_InJS")] to remap name of this class in JS.

For example, DuoCode.Dom.Document is defined (press F12 to see this):

[Js(Extern = true, Name = "Document")]

public class Document : Node, 




Im sorry i dont know what you are talking about "Scope_Name_InJS".... Its just a javascript object.
How would i know what "Scope_Name_InJS" is.

I am trying to make a bining for angular... "Scope" for me is the binding to the object that get returned
in angular.module.controller($scope)

I have created binding:
[Js(Extern = true)]
public class Scope : RootScopeService {}

and RootScopeService

[Js(Extern = true)]
public class RootScopeService
public extern dynamic this[string index] { get; }
[Js(Name = "$id")] public extern dynamic id { get; }
[Js(Name = "$parent")] public extern Scope parent { get; }
[Js(Name = "$root")] public extern Scope root { get; }
[Js(Name = "$new")] public extern Scope new_(bool isolate = false, dynamic parent = null);


This is working fine UNTIL i have to do a typeof() or GetType("MyNameSpace.Scope").

I dont know what you mean "Scope_Name_Js" ... As far as i know it does not a name... Or nothing i can see by inspecting the actually javascript object with console.log()

This is one of the main reasons I HATE JAVASCRIPT.... ITS SUCH A "LUCY GOOSEY" language.



Are you EVER going to put out ANY documentation. For instance what are the DOES and DONTS for creating bindings.

Please dont say look at qunit.d.cs. I have seen this already and its the most basic binding... but is absolutely NO HELP when trying to create REAL WORLD binding for something like Jquery and AngualrJS.

ALSO.... When i need to get into the "Nitty Griity" I would love to know about all under workings of the DuoCode.Runtime  stuff... But AGAIN i cant find ONE single piece of documentation on how to use these classes as well...

Basically you have a few SIMPLE examples, then Try Duo section AND THATS IT.... WE ARE ON OUR OWN TO JUST 'FIGURE' ALL THIS STUFF OUT... LIKE MAGIC OR SOMETHING


For the life of me i cant figure out what name you are talking about in javascript. If i look at angualr.js

it look like the the function $RootScopeProvider has a another function cal Scope in it that has a Scope.prototype onn it...  So PLEASE take a look at angular.js and tell me what i should have for a binding
that equals the angular js Scope.prototype class


Screw it... I'll just make every object that is not static window object use 'Object' name... Only drawback I see with that is that typeof will always show Just Object... But the underlying javascript bindings still work and since typeof dost not fail I can use with my inversion of control classes. I would still love some details on the ins and outs of creating bindings. All the samples are sooo simple.... That its no help when try to do a 1 for 1 conversion from say a typescript version of a js library to try and create matching bindings for the underlying js library using C#

I have investigated angular using TypeScript official definitions, found in:

All these so called "classes" like: Scope and RootScopeService are actually interfaces (there is no even one class at all there).

What it's mean that they are not having any class (that you are used too in C# behind), for example one private class can implement all these interfaces by Angular.

Thus the correct way to declare them is exactly what you suggested

[Js(Extern= true, Name = "Object"]

Regarding namespaces in JS: JS can also declare namespace, using function-class within function-class.

Thus when you import them to C# you should keep namespace / nested classes in mind, that was my point.


Login or Signup to post a comment