Roslyn Get Method Declaration from InvocationExpression

If you need the declaration of the method that you are calling, you can get that as follows. In the first step, you find out what method it is that is being called: var methodSymbol = context .SemanticModel .GetSymbolInfo(invocation, context.CancellationToken) .Symbol as IMethodSymbol; Remember that there are various reasons why the methodSymbol may be null … Read more

Can I use Roslyn for compile time code rewriting?

Compile time re-writing isn’t directly supported by Roslyn today, but syntactic and semantic transformations definitely are. In fact, take a look at the “ImplementNotifyPropertyChanged” sample included in the CTP to see something of what you want to do. The sample is implemented as a design time transformation in and IDE feature, but you can extract … Read more

Why do we get possible dereference null reference warning, when null reference does not seem to be possible?

This is effectively a duplicate of the answer that @stuartd linked, so I’m not going to go into super deep details here. But the root of the matter is that this is neither a language bug nor a compiler bug, but it’s intended behavior exactly as implemented. We track the null state of a variable. … Read more

C# 6.0 TFS Builds

For the compilation step, you have a couple of options: You can reference the Microsoft.Net.Compilers NuGet package on a per-project basis to use that version of the compilers. You can install the Microsoft Build Tools package that is part of the VS 2015 CTP package without installing all of VS. However, as @MrHinsh notes, these … Read more

Using C# 6 features with CodeDomProvider (Roslyn)

Update: March 2018 Word of caution, NuGet version 1.0.6 … 1.0.8 will not copy the /roslyn folder to the build output directory on non-web projects. Best stick with 1.0.5 https://github.com/aspnet/RoslynCodeDomProvider/issues/38 Run-time compilation using C#6 features requires a new compiler, as @thomas-levesque mentioned. This compiler can be installed by using the nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform. For desktop … Read more