How to implement more Mscorlib methods

 

What is mscorlib?

"mscorlib" is the name of the assembly that contains all the main classes and methods of the .NET Framework, such as the "DateTime" class, the "List<T>" class, and much more.

 

Why do I need to implement the methods?

The current version of CSHTML5 only implements a subset of the classes and methods contained in "mscorlib" (see "what is supported" for the full list). For example, if you attempt to call the unsupported method "DateTime.FromBinary(...)" in a CSHTML5 project, you will get a compilation error saying that the method is not yet supported. If you want it to be supported, you have the option of implementing the feature by yourself. This document will help you get started.

 

How are mscorlib methods implemented in CSHTML5?

The mscorlib methods are implemented in JavaScript. You can see their implementation by opening the following folder on your computer:

C:\Program Files (x86)\MSBuild\CSharpXamlForHtml5\InternalStuff\Libraries\

For example, the "DateTime" class is implemented in the file "JSIL.Bootstrap.DateTime.js". The generic class "List<T>" is implemented in the file "JSIL.Bootstrap.js".

Those files are part of the open-source JSIL framework, which is hosted at https://github.com/sq/JSIL.

Every time you compile your CSHTML5 project, those files are copied into the final output folder. More exactly: "ProjectFolder\bin\Debug\Output\Libraries\"

 

How to implement more methods of mscorlib?

There are 2 main steps:

1) Add the method that you wish to implement to the file "SupportedElements.xml". That file is located in the following folder (v1.0 Beta 10.1 or newer):

C:\Program Files (x86)\MSBuild\CSharpXamlForHtml5\InternalStuff\Compiler\

This will prevent the compiler from complaining that the method is not yet supported.

Note: when saving the file, Windows may tell you that you need administrator rights, because the file is located in a system folder. You can easily solve the issue for example by launching Notepad in administrator mode (to do so, right-click on the Notepad icon, and click "Run as administrator"), then open the file via the File=>Open menu, make the changes, and save the file;

 

2) Add new JavaScript code to the libraries. The libraries are located in the following folder:

C:\Program Files (x86)\MSBuild\CSharpXamlForHtml5\InternalStuff\Libraries\

You can add your code inside any of the files located in that folder.

Please note that, when testing, only the result in the browser is relevant. The result in the Simulator is not relevant because the Simulator does not use the JavaScript libraries (it uses the "real" mscorlib.dll assembly by Microsoft instead).

 

How to test more quickly without recompiling every time?

You can test more quickly by modifying the libraries contained in the "Output" folder instead of those contained in the "Program Files" folder (read the section above "How are mscorlib methods implemented in CSHTML5?" to better understand why). Please note that when you recompile your CSHTML5 project, the files located in the "Output" folder are overridden by those located in the "Program Files" folder, so you may lose your work if you have not backed it up somewhere else.

 

How to submit the contribution for inclusion in the next build of CSHTML5?

There are 2 possibilities:

1) Either you submit your contribution to the JSIL project, located on GitHub here. The CSHTML5 team will then merge the two codebases on a regular basis.

2) Or you can send your contribution to hello@cshtml5.com or post it on the CSHTML5 Forums for fast inclusion in the next build of CSHTML5.

 

Related Topics

 

Contact Us

Please click here for contact information.