Start a new topic

JsAttibute Extern Required For Delegates and Enums

Does C# Bindings (From Typescript) require the [JsAttribute Extern=True] for Enums and Delegates:


Example: Here is a Enum from Webix.. Should it be:

 

	public enum baselayoutEventName
	{
		onBindRequest,
		onDestruct
	}


Or

        [Js(Name="Object", Extern=true)]
	public enum baselayoutEventName
	{
		onBindRequest,
		onDestruct
	}


And Delegates:

	public delegate string WebixTemplate (params any[] args);


OR

        [Js(Name="Object", Extern=true)]
	public delegate string WebixTemplate (params any[] args);

 

1 Comment

1) From my quick view, baselayoutEventName is string not enum, in TS it's declared as a two value string:

type baselayoutEventName ='onBindRequest'|'onDestruct';


So in C# with DuoCode define baselayoutEventName just as a string.

using baselayoutEventName  = string;

Add consts with these values in some class.


2)

[Js(Extern=true)]

public delegate string WebixTemplate (params any[] args); should work.

Tip if you define it inside [Js(Extern=true)] class already no need to put [Js(Extern=true)] on the delegate itself ("Extern=true" is inherited from declared classes).


Just recall that such a type is not present (it's just a declaration), so thing like:

- typeof(WebixTemplate) fails

- List<WebixTemplate> will fail too

- event WebixTemplate fails


Another more low-level way, more robust, not strongly-typed and requires manual binding, similar to pure JS:

use JsFunction type instead (same as Function in JS).

in order to call Js.function(someHandler).bind(this).

Login or Signup to post a comment