Skip to main content

Syntax Transformer

Unity Playworks Plugin uses Bridge.NET to compile C# code into JavaScript. Bridge.NET is a powerful tool that allows developers to write C# code and compile it into JavaScript. However, Bridge.NET does not support the latest C# features. To overcome this limitation, Unity Playworks Plugin has developed a tool called the Syntax Transformer.

The Syntax Transformer is a tool that allows developers to use the latest C# features in their Unity Playworks Plugin projects. The tool transforms the latest C# syntax into an older version of C# that is supported by Bridge.NET. This allows developers to take advantage of the latest C# features without worrying about compatibility issues.

C# features: Bridge.NET vs. Bridge.NET with Syntax Transformer

FeatureBridgeBridge + SyntaxTransformer
C# 7.0-7.3 features
Out variablesSupportedSupported
Tuples and deconstructionUnsupportedSupported
Pattern matchingSupportedSupported
Local functionsUnsupportedSupported
Expanded expression bodied membersSupportedSupported
Ref locals and returnsSupportedSupported
DiscardsUnsupportedSupported
Throw expressionsUnsupportedSupported
default literal expressionsUnsupportedSupported
in modifier on parametersSupportedSupported
Non-trailing named argumentsSupportedSupported
== and != with tuple typesSupportedSupported
C# 8.0 features
Null-coalescing assignmentUnsupportedSupported
Pattern-matching enhancementsUnsupportedUnsupported
Readonly membersUnsupportedSupported
Static local functionsUnsupportedSupported
Using declarationsUnsupportedSupported
Enhancement of interpolated verbatim stringsUnsupportedSupported
Disposable ref structsUnsupportedUnsupported
Stackalloc in nested expressionsUnsupportedUnsupported
Unmanaged constructed typesUnsupportedUnsupported
Default interface methodsUnsupportedUnsupported
Indices and rangesUnsupportedUnsupported
Asynchronous streamsUnsupportedUnsupported
Asynchronous disposableUnsupportedUnsupported
C# 9.0 features
Lambda discard parametersUnsupportedSupported
Target-typed newUnsupportedSupported
Pattern-matching enhancementsUnsupportedUnsupported
Static anonymous functionsUnsupportedSupported
Lambda discard parametersUnsupportedSupported
Target-typed conditional expressionUnsupportedUnsupported
Local function attributeUnsupportedUnsupported
Native-sized integersUnsupportedUnsupported
Skip localsinitUnsupportedUnsupported
RecordsUnsupportedUnsupported
Init-only settersUnsupportedUnsupported
Covariant returnsUnsupportedUnsupported
Top-level statementsUnsupportedUnsupported
Function PointersUnsupportedUnsupported

Syntax Transformer: How it works

Syntax Transformer is integrated into the Unity Playworks Plugin and runs automatically when you compile your project. The Syntax Transformer is designed to be transparent and seamless, so you don't need to worry about configuring or using it. When you compile your project, the Syntax Transformer all the C# sources are copied into a temporary directory (LunaTemp/stage3/processed-scripts) and transformed into an older version of C# that is supported by Bridge.NET. The transformed sources are then compiled into JavaScript using Bridge.NET.

Syntax Transformer: Troubleshooting

If Syntax Transformer cannot process your C# source, it will issue an LP2008 error in the project diagnostics. In this case, the compilation process will continue, but you will be limited to using C# features up to version 7.3. Please report the issue to the Unity Playworks Plugin team so that we can investigate and fix it.