How to do it...

  1. Open Roslyn.sln at the root of the Roslyn repo in VS2017.
  2. Open source file <%ROOT%>srcCompilersCSharpPortableParserLanguageParser.cs.
  3. Navigate to private method IsPossibleParameter (line 4060) and add the highlighted || clause to the default case return statement:
default:
return IsPredefinedType(this.CurrentToken.Kind) || GetModifier(this.CurrentToken) != SyntaxModifier.None;
  1. Navigate to private method ParseParameterModifiers (line 4234), and replace the existing while (IsParameterModifier(this.CurrentToken.Kind, allowThisKeyword)) with a while (true) loop, add the following if statement at the start of the while loop:
while (true)
{
if (!IsParameterModifier(this.CurrentToken.Kind, allowThisKeyword))
{
if (GetModifier(this.CurrentToken) != SyntaxModifier.None)
{
// Misplaced modifier
var misplacedModifier = this.EatToken();
misplacedModifier = this.AddError(misplacedModifier, ErrorCode.ERR_BadMemberFlag, misplacedModifier.Text);
modifiers.Add(misplacedModifier);
continue;
}

break;
}
...
  1. Build the solution.
  2. Set VisualStudioVisualStudioSetup.Next.csproj as the startup project and click on Ctrl + F5 to start a new VS instance with the locally built compiler and IDE toolset.
  3. Create a new C# class library project, say ClassLibrary, and add the following code:
class Class
{
static void M(readonly int param)
{
}
}
  1. Verify that there is a single CS0106 diagnostic in the error list for the invalid readonly modifier and also that the editor has a single squiggle.
  1. Build the project and verify that the build output has a single CS0106 diagnostic.
You can view all the parser changes made in this recipe at https://github.com/mavasani/roslyn/commit/02b7be551b46fa9a8e054c3317bc2ae7957b563c.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset