Complete the Clr types managed by SharpKit

35 views
Skip to first unread message

jre...@gmail.com

unread,
Mar 18, 2015, 5:38:48 AM3/18/15
to shar...@googlegroups.com
Hi everyone,

I hope this is the good place to ask my question - i'm a newbie on SharpKit so maybe there is an answer seomwhere else, but i was not able to find it.

I'm trying to use SharpKit to integrate the Windows Forms Designer in web forms (!!).

Basically, the process works like this :

1. "SharpKitLib" Library
A library called "SharpKitLib" uses SharpKit and provides a javascript implementation for all common windows forms controls (Component, Control, TextBox, Panel, etc.). 
The implementation of the controls requires JsClr and so needs a compilation (<script>Compile(); </script>) and there is a namespace mapping between "SharpKitLib" namespace and "System" namespace.
For instance, the class "SharpKitLib.Drawing.Point" in C# will produce "System.Drawing.Point" in Javascript.

This part works really like a charm.

2. Using the tool 
The developer, when he wants to use the project, has just to create a classical Windows Form project, and uses the designer to make his job.
Each class in this project, especially the Windows Form controls, must be decorated with [JsTypeAttribute] and will be generated in Javascript.

At the end, we have just to deploy the javascript files produced by "SharpKitLib" assembly and the developper custom assembly, and the web page works exactly like the Window form original project :)
The goal is to win time when make back office and repetitive screens, and then to put "SharpKitLib" open source.

My problem is on point 2, on "InitializeComponent()" designer method, we can have for example:
In C#: 
> this.Location = new System.Drawing.Point( 100, 100 );
In Js:
>> this.set_Location( new System.Drawing.Point.ctor$$Int32$$Int32( 100, 100 ) );
And i expect to have :
>> this.set_Location( new System.Drawing.Point( 100, 100 ) );

The "System.Drawing.Point" class is generated like a JsClr class. In other words, SharpKit considers that this type is a part of the framework, and will generate appropriate code that can be handled by JsClr.js. 
But in my case, i provide the javascript implementation of a Clr type - System.Drawing.Point in this example - that SharpKit do not manage natively. 

Is there any way to fix my problem :
- Generate the good code above (remove the ".ctor$$Int32$$Int32") ?
OR
- Generate "SharpKitLib" code like a clr one (with all ...$$...() methods)  ?

Thank you very much in advance.

Sebastian Loncar

unread,
Mar 18, 2015, 8:34:34 AM3/18/15
to SharpKit Support
Hi,
your idea sounds awesome!

You can do this:
[assembly: JsType(NativeOperatorOverloads = true, TargetType = typeof(System.Drawing.Point))]

But please keep it mind, that javascript itself does not support method overloading.



Lieben Gruß,
Sebastian

--
You received this message because you are subscribed to the Google Groups "SharpKit Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharpkit+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sebastian Loncar

unread,
Mar 18, 2015, 8:37:14 AM3/18/15
to SharpKit Support
Sorry, i meant "NativeOverloads = true"


Lieben Gruß,
Sebastian

Jean Rémy Cohen

unread,
Mar 18, 2015, 8:40:39 AM3/18/15
to shar...@googlegroups.com
Hi Sebastian,

Thank you so much for your quick answer, i will try tonight when i will work on the project.
I will notice you if it worked, and when the lib will be finish i will provide you a copy of the source code, if you are interested.

Very best regards,
JR



--
You received this message because you are subscribed to a topic in the Google Groups "SharpKit Support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sharpkit/RaXkXDbRoFY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sharpkit+u...@googlegroups.com.

jre...@gmail.com

unread,
Mar 18, 2015, 10:54:57 AM3/18/15
to shar...@googlegroups.com, jre...@gmail.com
Thank you very much, it works very well.

May i ask you some other questions :

1. Can I do that concerning the protected/public methods of the class UserControl or Form. In windows forms, you create a form that inherits from one of these two classes. 
For now, SharpKit generates me "this.ResumeLayout$Boolean(false);" instead of "this.ResumeLayout(false)", in the InitializeComponent() method of the form/usercontrol.
I tried to play with the JsTypeAttribute with TargetType=typeof(System.Windows.Forms.Form) but with no success.

2. typeof(X) returns NULL in javascript, where X is a C# class decorated with [JsType(JsMode.prototype, FileName="...")]. I had a look inside the JsClr.js code, and for the moment i put a hack like :
<script src="Script/MyNamespace.MyClass.js" />
<script>MyNamespace.MyClass._type = { typeName:'MyNamespace.MyClass', assemblyName:'MyAssembly' } </script>

It allows Typeof( X ) in javascript to return me this value, but it is probably not compatible with the "Type" javascript representation you have in JsClr.js.
Any idea ?

In all cases, thank you very much for your help, it allows me to continue on this project and not waste time on subjects i do not yet know very much :)

Sebastian

unread,
Mar 20, 2015, 3:47:04 AM3/20/15
to shar...@googlegroups.com, jre...@gmail.com
Hi,
did you tried to rename the method manually? Please have a look at this example:
https://github.com/SharpKit/SharpKit-SDK/blob/master/Frameworks/JsClr/System/Collections/Generic/Interfaces.cs#L177-L198

You could re-implement the forms class and assign the JsMethod Attribute and set the Name manually.

But you can do it globally without re-implement the class:
[assembly: JsMethod(TargetType = typeof(System.Windows.Forms), TargetMethod = "ResumeLayout", Name = "ResumeLayout", NativeOverloads = true)]

I hope i could help you. If not, please send a minimalized example as zip file. (A minimalized example have in best case not more than round about 20-30 lines of code).

Greetings,
Sebastian
Reply all
Reply to author
Forward
0 new messages