Start a new topic

Support for Any<> class

Can you please add this any class... it would be great for general usage in duo code.

you can do stuff like this (Which i am using in my TypeScript To C# Converter to support typescript multiple options like- arg: <string, bool>):


public class Test {
 public Any<string, HTMLElement> container { get; set; }

Test test = new Test();
test.container = "elid";


test.container = document.createElement("div");


Right now i use it my library toolkit... but I'm sure others can make great use of this class for general purpose usage (PLUS: Compiler Supported..So will error if not one of the any types)

Also... the typescript converter (Ported from Michael Cheers Bridge TypeScript converter) i will be releasing as open source... I use Any<> instead of making everything dynamic... Much stronger API's for the native javascript library...

For example: Here is my bootstrap ModalOptions... Note the backdrop field:


	[Js(Name = "Object", Extern = true)]
	public class ModalOptions
		[Js(Name = "backdrop")]
		public extern Any<bool, string> backdrop { get; set; }
		[Js(Name = "keyboard")]
		public extern bool keyboard { get; set; }
		[Js(Name = "show")]
		public extern bool show { get; set; }
		[Js(Name = "remote")]
		public extern string remote { get; set; }


Way Kool...

(6.29 KB)

Please use our Union<T1, T2, ...> class instead, available from DuoCode 2.0.

It way better and supports >100 implicit down and up casts like:

T1 -> T2 | T1


T1 | T2 | T3 -> T3 | T1

Enjoy I have attached out basic tests as well.

(1.26 KB)

Of course in generated .d.ts it results as T1 | T2.

Name Union inspired from TypeScript as well, see

Thanks for the heads up on the Union... I have removed the Any.cs class and replaced with the Builtin Union<T1, T2>

Check out FORUM POST DuoCode TypeScript Converter for example bootstrap.d.cs and webix.d.cs

Union on supports MAX 4 Types Union<T1, T2, T3, T4>... Jquery has several Unions that have 6 or 7 param types... Can you can Union<> support at least 12 Types... Union<T1,...,T12>

4 is way too low for typescript conversion 

We will add more in next version.

DuoCode 2.2 will support for upto 8 types.
Login or Signup to post a comment