Bridge v1.8 Released

Welcome to version 1.8 of Bridge.NET. It comes packed with bug fixes, performance improvements and some cool new features. Before start exploring what’s new, make sure you have the latest version installed in your Windows, Linux or Mac OS. If you are working on Windows with Visual Studio we do provide a VSIX installation package that supports versions 2012, 2013 and the brand new Visual Studio 2015 release.

Multi-Platform OS Support

winlinuxmacBridge’s purpose is to provide you with JavaScript that can run everywhere. Also, we want the Bridge C# to JavaScript compiler itself to be able to run on multiple platforms.

Currently Bridge runs on Windows, Linux and Mac OS and supports both the Visual Studio and Visual Studio Code IDEs from Microsoft as well as the Xamarin Studio (MonoDevelop) from the Mono community. Also, the Bridge.NET download page has been redesigned to make it easier for you to choose the right installation method for your project.

Please, read the related blog post if you are further interested in our efforts to keep Bridge multi-platform.

JSDoc Support

JSDoc is now supported by Bridge.NET. Very briefly, JSDoc is a markup language used to annotate JavaScript source code files. By default, Bridge automatically translates any XML documentation found in the C# code into JSDoc comments in the generated JavaScript files, as shown below.

namespace Demo
{
    /// <summary>
    ///  This class performs an important function.
    /// </summary>
    public class App
    {
    }
}
 
  
/* global Bridge */

/** @namespace Demo */

/**
 * This class performs an important function.
 *
 * @public
 * @class Demo.App
 */
Bridge.define(‘Demo.App’); 

 

To override the default behavior, the new generateDocumentation configuration property is provided. The follow table summarizes the available values that can be set in bridge.json.

generateDocumentation Description
None Produce no JSDoc comments
Basic Translate existing XML Doc comments in the C# code into JSDoc comments both in the generated JavaScript files and the TypeScript definitions, if any.
Full Annotate all the generated JavaScript and TypeScript definitions with JSDoc comments.
Minified version of the generated JavaScript is not affected by the JSDoc feature.

For example, setting generateDocumentation to Full:

JSbridge.json
{
    “generateDocumentation”:  “Full”
} 

will have the C# code on the left produce the JavaScript on the right:

namespace Demo
{
    /// <summary>
    ///  This class performs an important function.
    /// </summary>
    public class App
    {
        [Ready]
        public static void Main()
        {
            Global.Alert(“Success”);
        }
    }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
/* global Bridge */

/** @namespace Demo */

/**
 * This class performs an important function.
 *
 * @public
 * @class Demo.App
 */
Bridge.define(‘Demo.App’, {
    statics: {
        config: {
            init: function () {
                Bridge.ready(this.main);
            }
        },
        /**
         * @static
         * @public
         * @this Demo.App
         * @memberof Demo.App
         * @return  {void}
         */
        main: function () {
            Bridge.global.alert(“Success”);
        }
    }
}); 

With the Bridge 1.7.0 release we also introduced generation of TypeScript Definition files (.d.ts) by setting generateTypeScript: true in your projects bridge.json configuration file. With the new generateDocumentation functionality, documentation comments are also automatically translated from C# and added to your projects generated .d.ts file(s).

namespace Demo
{
    /// <summary>
    ///  This class performs an important function.
    /// </summary>
    public class App
    {
        [Ready]
        public static void Main()
        {
            Global.Alert(“Success”);
        }
    }
}
 
 
 
 
 
  
/// 

declare module Demo {
    /** @namespace Demo */

    /**
     * This class performs an important function.
     *
     * @public
     * @class Demo.App
     */
    export interface App {
    }
    export interface AppFunc extends Function {
        prototype: App;
        new (): App;
        main(): void;
    }
    var App: AppFunc;
} 

New PreserveMemberCase Configuration Property

Bridge favors lower CamelCase in the naming of class members (methods, constructors, etc). To override the default behavior, the PreserveMemberCase configuration property is introduced. When set to true, all class members will retain the first letter of their name as in the C# code. A notable example is the Main method, which will be named exactly the same both in C# and in JavaScript.

You can always find all available configuration properties, their values and descriptions in the Global Configuration knowledge base article.

Testing, Testing, Testing

We are continuously unit testing all aspects of Bridge from core functionality to LINQ and TypeScript. Version 1.8 is proudly accompanied by more than 3500 unit tests, all publicly available on the online Bridge.NET Test Library. Right, that’s worthy of a screenshot.

Screenshot 2015-08-17 10.12.18

Live Bridge TypeScript Support

The Live compiler has been extended to let you view the generated TypeScript Definition file. This is something we worked on after the 1.7 release and didn’t have the chance to present in this blog, but it’s worth mentioning.

live-ts-1Live Bridge.NET shows the generated JavaScript, by default. To view the related TypeScript defintions, click the TypeScript button found next to the familiar Run button. Notice the green JS indicator change to blue TS and the button now reads JavaScript acting as a toggle between the two outputs.

The screenshot below shows the TypeScript definitions generated for the C# code loaded by the Live compiler, by default.
live-ts-2

Decimal Support Added

Another huge feature of 1.8.0 is support for the complete C# Decimal type, including 28 decimal precision when compiled into JavaScript.

We had to spend a little extra time on Decimal which pushed back the 1.8.0 release, but we felt strongly this was a must have feature and wanted to ensure the functionality was well covered by unit tests.

decimal d = 1.0M;

// Test decimal.
if (d == 1.0M)
{
    Console.WriteLine(d);
}

decimal y = 0.5M;

// Add decimal.
y += d;

Console.WriteLine(y);

// Subtract and multiply decimal.
y -= (d * 2);

Console.WriteLine(y); 
var d = Bridge.Decimal(1.0);

// Test decimal.
if (d.equalsT(Bridge.Decimal(1.0))) {
    console.log(d.toString()); // 1
}

var y = Bridge.Decimal(0.5);

// Add decimal.
y  = y.add(d);

console.log(y.toString()); // 1.5

// Subtract and multiply decimal.
y  = y.sub((d.mul(Bridge.Decimal(2))));

console.log(y.toString()); // -0.5
  

Support for Decimal introduces a unique and significant advancement for C# to JavaScript compiler projects and because of the precision now available to Financial and Scientific projects, this will undoubtedly open up amazing new possibilities for Bridge.NET.

More Information

Download

CDN : bridge.js or bridge.min.js

Official Release stamp in GitHub

Comparing v1.7 vs v1.8 changes

41 Defects Fixed

16 New Features Added

Leave a Reply

Your email address will not be published. Required fields are marked *

Markdown and code formatting supported in comments, including use of code formatting shortcodes ([cs], [js], [code], [html])