Roslyn: Feature: Build 2016 code generation/replace-original feature

Created on 14 Apr 2016  路  5Comments  路  Source: dotnet/roslyn

I don't know if there is a thread for this extremely cool feature showcased at Build.
Basically, the new syntax for partial classes which replace original properties is:

replace public string FirstName
{
  get { return original; }
  set { original = value; }
}

I have a couple of questions here

  1. Are keywords replace and original final or will you change them?
  2. Code generation is rather crude, will you create something better than just string concatenation?
  3. How does code generation actually work? I guess you have a branch or doc somewhere?
Area-Compilers New Language Feature - ReplacOriginal Question

Most helpful comment

They should really make feature branch docs/summaries. Going thru commits are tedious.

All 5 comments

See #5561 and #5292.

Edit: The branch is features/generators.

They should really make feature branch docs/summaries. Going thru commits are tedious.

@leppie Isn't Language Feature Status what you want? (Though it doesn't have issue link for Source Generation and says that its branch is future.)

3, How does code generation actually work? I guess you have a branch or doc somewhere?

I found this live document really valuable:

https://github.com/dotnet/roslyn/blob/features/generators/docs/features/generators.md

Guess that kind of answer [2] from the OP too.

I'd structure the interface more functionally:

public abstract class SourceGeneratorContext
{
    public abstract GeneratorResult Process(Compilation compilation);
}

sealed class GeneratorResult { IEnumerable<Diagnostic>, IEnumerable<AddedCompilationUnit> }

Input goes in, nothing is modified/written/stored, output comes out. This might seems like a small difference but given that this initial release is the only shot we have at defining this class it seems worth the change.

Was this page helpful?
0 / 5 - 0 ratings