Start a new topic

Unsealed Union Class

Can you PLEASE un-seal the Union class... I need to be able to SUBCLASS a Union.


Note: In typescript you can a UnionType:

 

type MyElement = HTMLScriptElement;
type MyCustomElements = MyElement | HTMLScriptElement;

 

How i need to resolve this in .NET: Right now i have a class i created called Alias but would be a lot BETTER if CAN USE Union<T1,T2>: Also NOTE... NEED A Union<T1>just to be able to make an ALIAS that can be implicitly set. Example:


 

	#pragma warning disable CS0626
	public class MyElement : Alias<HTMLLinkElement>
	{
		public extern static implicit operator MyElement(HTMLLinkElement value);
		public extern static implicit operator HTMLLinkElement(MyElement value);
	}
	#pragma warning restore CS0626

	#pragma warning disable CS0626
	public class MyCustomElements : Alias<MyElement, HTMLScriptElement>
	{
		public extern static implicit operator MyCustomElements(MyElement value);
		public extern static implicit operator MyElement(MyCustomElements value);
		public extern static implicit operator MyCustomElements(HTMLScriptElement value);
		public extern static implicit operator HTMLScriptElement(MyCustomElements value);

	}
	#pragma warning restore CS0626

 


CAN YOU PLEASE... Make Union NOT sealed and PLEASE make a Union<T1> so

my c# bindings for DuoCode can use the Native Union class and NOT have a dependency on my Alias class (Which i my poor man version of your Union class since its sealed)


Example my alias class (Up to 8 types):

 

	public class Union
	{
		public static bool Is<T>(T anything) { return anything is T; }
	}

	[Js(Name = "Object", Extern = true)]
	public class Alias<T1> : Union
	{
		protected extern Alias();
		public static extern implicit operator Alias<T1>(T1 t);
		public static extern explicit operator T1(Alias<T1> value);
	}

	[Js(Name = "Object", Extern = true)]
	public class Alias<T1, T2> : Union
	{
		protected extern Alias();
		public static extern implicit operator Alias<T1, T2>(T1 t);
		public static extern implicit operator Alias<T1, T2>(T2 t);
		public static extern explicit operator T1(Alias<T1, T2> value);
		public static extern explicit operator T2(Alias<T1, T2> value);
	}

	[Js(Name = "Object", Extern = true)]
	public class Alias<T1, T2, T3> : Union
	{
		protected extern Alias();
		public static extern implicit operator Alias<T1, T2, T3>(T1 t);
		public static extern implicit operator Alias<T1, T2, T3>(T2 t);
		public static extern implicit operator Alias<T1, T2, T3>(T3 t);
		public static extern explicit operator T1(Alias<T1, T2, T3> value);
		public static extern explicit operator T2(Alias<T1, T2, T3> value);
		public static extern explicit operator T3(Alias<T1, T2, T3> value);
	}

 


PLEASE!!!


Login or Signup to post a comment