smwikipedia
smwikipedia

Reputation: 64205

Strange property assignment syntax?

What's the following syntax? It's not compiling but it's from an old codebase.

private static JsonSerializer JsonSerializer { get; } = new JsonSerializer()

The compiler complains that:

Error   1   Invalid token '=' in class, struct, or interface member declaration.

Upvotes: 0

Views: 126

Answers (2)

Rsh
Rsh

Reputation: 7742

What you have mentioned is Getter-only auto-properties and it's not part of C#, not yet ! It's part of new language features of C#. They've been implemented using Roslyn, .Net compiler platform.

Roslyn provides you with access to interior parts of C# and VB compiler. You have full access to compilation results and even you can manipulate C# itself.

There are dozens of other feature that you'll see in C# 6, such as Declaration expressions :

int.TryParse(s, out var x);

Exception filters :

catch(E e) if (e.Count > 5) { … } 

To see the full list of new language featurs and their current status, check out this entry in official Roslyn page on codeplex.

If you're intersted in the idea and want to dig in, I would recommend watching this build conference video. It can give you the big picture of the role of Roslyn in the furure of C#.

Upvotes: 3

smwikipedia
smwikipedia

Reputation: 64205

After searching around, it turns out to be the .NET compiler platform (Roslyn).

Upvotes: 0

Related Questions