A pre-release of the next major version of Bridge has been published to NuGet and it’s packed with features. We’re excited to announce the release of Bridge 17.0.0-beta.

Currently Bridge 17.0.0-beta is only available from NuGet using the -pre flag. Install to your project using the following command from the NuGet Package Manager Console:

Install-Package Bridge -pre

The Bridge .exe file, .zip packages, and full source code, are also available from GitHub Releases.

C#7 Language Features

Bridge now fully supports the entire set of C#7 language features, including all of the following:

is expressions

switch pattern matching

local functions

expression-bodied members

binary literals

digit separators

ValueTuple

out variables

throw Expressions

Check out our new CSharp7 Deck for a sample demonstrating many of the new C#7 syntax features

Not only are the C# 7.0 language features now supported, but we’ve also included support for the latest C# 7.1 and 7.2 features too, including:

default literals (C# 7.1)

async Main method (C# 7.1)

inferred Tuple element names (C# 7.1)

readonly structs (C# 7.2)

private protected access modifier (C# 7.2)

leading underscores in numeric literals (C# 7.2)

non-trailing named arguments (C# 7.2)

Please see Issue #2455 and #3491 for details.

Two New Rules

Rules allow for refinement of the generated JavaScript syntax created by the Bridge compiler. Rules can be configured as [Rules] Attributes or within the rules node of the project bridge.json file.

We’ve added two new Rules in v17.0 which can help optimize your Bridge application at runtime.

New InlineComment Rule

By default, Bridge will copy over inline // comments from the C# into the JavaScript, but this action can now be modified using the new InlineComment Rule.

The following sample demonstrates a simple scenario where two different Methods are configured with InlineComment Rules using the Plain and Managed options. The default functionality is Managed , so unless otherwise configured by an InlineComment Rule, C# comments will be copied into the runtime app.

Example (Deck)

public class Program

{

[Rules(InlineComment = InlineCommentRule.Plain)]

public static void InlineComment1()

{

// Comments not copied to .js

var msg = "no comment above";

}



[Rules(InlineComment = InlineCommentRule.Managed)]

public static void InlineComment2()

{

// Inline comments copied to .js

var msg = "comment above";

}

}

The above sample will generate the following JavaScript for the two Methods.

InlineComment1: function () {

var msg = "no comment above";

}, InlineComment2: function () {

// Inline comments copied to .js

var msg = "comment above";

}

The [Rules] attribute can be configured at any point of the entity hierarchy, including at the Assembly, Class, or Method levels.

In addition to the existing Rules that can be configured using C# Attributes, your project bridge.json file can be configured to apply the rules globally across an entire project without having to modify the C#.

The following sample demonstrates the configuration block required for adding the inlineComment rule to your bridge.json.

// Default is "Managed".

"rules": {

"inlineComment": "Plain"

}

Please see Issue #3517 for details.

New ExternalCast Rule

A new ExternalCast rule has been added to instruct Bridge on how to treat casting of external classes.

The following sample demonstrates a simplified but typical scenario where a new HTML Element is created and then cast to a specific HTML Element type.

By default (`Managed`), Bridge will perform a runtime cast operation as another type safety check, but this may not be the desired action within your application.

Applying the ExternalCast Rule Attribute provides an option to simplify the generated runtime code.

public class Program

{

[Rules(ExternalCast = ExternalCastRule.Managed)]

public static void ManagedCast()

{

var el = (HTMLDivElement)document.createElement("div");

}



[Rules(ExternalCast = ExternalCastRule.Plain)]

public static void PlainCast()

{

var el = (HTMLDivElement)document.createElement("div");

}

}

The above sample will generate the following runtime code.

ManagedCast: function () {

var el = Bridge.cast(document.createElement("div"), HTMLDivElement);

}, PlainCast: function () {

var el = document.createElement("div");

}

As with all Rules, the ExternalCast Rule can be applied globally to an entire project by configuring the externalCast node within your project bridge.json.

// Default is "Managed".

"rules": {

"externalCast": "Plain"

}

Please see Issue #3516 for details.

Breaking Changes

There are a few relatively minor Breaking Changes in the 17.0 release.

Notation Enum Values

Two values of the Notation enum have been renamed and may affect your project if you have used the [Convention] Attribute.

The old UpperCamelCase value has been renamed to PascalCase and similarly, the LowerCamelCase value has been renamed to just CamelCase.

// Old UpperCamelCase

[Convention(Notation.LowerCamelCase)]

public void DoSomething() { } // .doSomething() // New PascalCase

[Convention(Notation.PascalCase)]

public void DoSomething() { } // .doSomething() // Old LowerCamelCase

[Convention(Notation.UpperCamelCase)]

public void DoSomething() { } // .DoSomething() // New CamelCase

[Convention(Notation.CamelCase)]

public void DoSomething() { } // .DoSomething()

Please see Issue #3433 and #3434 for details.

Documentation for Convention Attribute.

Moved [Ready] Attribute from Html5 to Bridge

We’ve moved the [Ready] Attribute into the Bridge project.

This change is not likely to cause a compilation error in your project, but if it does, the fix is very simple. You can do either of the following:

Add using Bridge; to your file, or Prefix using [Bridge.Ready] instead of just [Ready]

If your startup method is named static void Main() you do not require [Ready] and it should be removed.

[Ready]

public static void Init()

{

Console.WriteLine("This will auto-run on page load");

} // No [Ready] required for Main

public static void Main()

{

Console.WriteLine("This will auto-run on page load");

}

Please see Issue #3431 for details.

Keys method removed from Object class

In previous releases, Bridge had a .Keys() method on the base C# Object class, but this method has been removed as of Bridge 17.0.

The same functionality is still easily available from Retyped when using the Retyped.Primitive.Object.keys(object o) method.

The following sample demonstrates creating an anonymous C# object and writing the resulting keys string array to the Console.

Example (Deck)

using Retyped.Primitive; public class Program

{

public static void Main()

{

var obj = new

{

Name = "Frank",

Role = "Admin",

Company = "CompanyX"

};



var keys = Object.keys(obj);



System.Console.WriteLine(keys);

}

} // Name,Role,Company

Please see Issue #3203 for details.

Archiving Bridge.Html5

The Bridge.Html5 project has been moved out of the main Bridge project into a new home within the Bridge Frameworks repository. As part of this move, we’re officially archiving the Bridge.Html5 project and will be focusing our efforts on enhancements to Retyped.

Until the future Bridge 18.0 release, updated Bridge.Html5 packages will be published to NuGet with each new release, although the package will no longer be included in the default Bridge Project Templates for Visual Studio. If your project contains a NuGet package reference to Bridge.Html5, it will continue to work as expected with no changes required in your project, but we do encourage you to upgrade to Retyped.

The Retyped.dom package is functionally equivalent to Bridge.Html5, although there are some differences in the syntax style, such as Bridge.Html5 is configured as PascalCase in C#, whereas Retyped.dom is CamelCase.

The following C# snippet demonstrates the naming convention difference between the two packages.

Example

// Create a new <div>

var el = new HTMLDivElement(); // Bridge.Html5

Document.Body.AppendChild(el); // Retyped.dom

document.body.appendChild(el);

When using Retyped, in many scenarios JavaScript can be copied directly without modification from a .js file into a .cs file and it will be valid C#.

Both packages will generate the same JavaScript, although Retyped.dom includes the entire JavaScript DOM API, while Bridge.Html5 is missing some entities.

Roadmap Coming Soon

We’re working on an official Roadmap document that will outline the next year of development for Bridge.NET and anticipate publishing within the coming weeks.

The following list provides a sneak peak at what’s on the drawing board for upcoming Bridge releases, but not necessarily in the order that will be implemented:

Loading and running Web Assembly (WASM) modules Dual .NET Core and .NET Framework .csproj format support Four new Visual Studio Project Templates dotnet-cli Project Templates Modularization of Bridge and System runtime classes Compile time tree-shaking to reduce runtime footprint Ultra small bootstrapper for Application startup Hot module reloading

Summary

Many other bugs were fixed and enhancements included in Bridge 17.0. The full list of closed issues has been logged on GitHub.

We’re actively improving Bridge 17.0 and plan to make the final release in a few weeks if all goes well. Please try the 17.0.0-beta release in your project and let us know if you find any issues (Forums | GitHub).

Did you know Bridge is community supported free open-source software? We fund development of Bridge and Retyped by providing value-added Premium Plugins and expedited Premium Support services. Please check out the Bridge Pro and Enterprise Premium options.

Thanks for your interest in Bridge.NET!

P.S. Retyped!

A massive new release of Retyped is coming soon. Retyped is once again fully up to date with the latest releases of TypeScript 2.8 and DefinitelyTyped. We will be including improved C# syntax support for 3000+ JavaScript libraries; an increase of 600+ new libraries since the last release. Woohoo!!