When trying to use a C# 7.1 feature, like default literal, RoslynQuoter fails with an exception. I think it should set language version to latest, to avoid this kind of problem.
As an example, this code:
class C
{
void A(int? x = default)
{
}
}
Produces this exception:
Microsoft.CodeAnalysis.Scripting.CompilationErrorException: (4,17): error CS8107: Feature 'default literal' is not available in C# 7.
Please use language version 7.1 or greater.
at Microsoft.CodeAnalysis.Scripting.ScriptBuilder.ThrowIfAnyCompilationErrors(DiagnosticBag diagnostics, DiagnosticFormatter formatter)
at Microsoft.CodeAnalysis.Scripting.ScriptBuilder.CreateExecutor[T](ScriptCompiler compiler, Compilation compilation, Boolean emitDebugInformation, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Scripting.Script`1.GetExecutor(CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Scripting.Script`1.RunAsync(Object globals, Func`2 catchException, CancellationToken cancellationToken)
at Quoter.Evaluate(String apiCallString, Boolean normalizeWhitespace)
at Quoter.AddModifyingCall(ApiCall apiCall, MethodCall methodCall)
at Quoter.AddModifyingCalls(Object treeElement, ApiCall apiCall, List`1 values)
at Quoter.QuoteNode(SyntaxNode node, String name)
at Quoter.QuotePropertyValue(SyntaxNode node, PropertyInfo property)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Quoter.QuotePropertyValues(SyntaxNode node)
at Quoter.QuoteNode(SyntaxNode node, String name) at Quoter.Quote(Object treeElement, String name)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at Quoter.QuoteList(IEnumerable syntaxList, String name)
at Quoter.QuotePropertyValue(SyntaxNode node, PropertyInfo property)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Quoter.QuotePropertyValues(SyntaxNode node)
at Quoter.QuoteNode(SyntaxNode node, String name)
at Quoter.QuotePropertyValue(SyntaxNode node, PropertyInfo property)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Quoter.QuotePropertyValues(SyntaxNode node)
at Quoter.QuoteNode(SyntaxNode node, String name)
at Quoter.Quote(Object treeElement, String name)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at Quoter.QuoteList(IEnumerable syntaxList, String name)
at Quoter.QuotePropertyValue(SyntaxNode node, PropertyInfo property)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Quoter.QuotePropertyValues(SyntaxNode node)
at Quoter.QuoteNode(SyntaxNode node, String name)
at Quoter.Quote(Object treeElement, String name)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at Quoter.QuoteList(IEnumerable syntaxList, String name)
at Quoter.QuotePropertyValue(SyntaxNode node, PropertyInfo property)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Quoter.QuotePropertyValues(SyntaxNode node)
at Quoter.QuoteNode(SyntaxNode node, String name)
at Quoter.Quote(Object treeElement, String name)
at Quoter.Quote(SyntaxNode node)
at QuoterService.Controllers.QuoterController.Get(String sourceText, NodeKind nodeKind, Boolean openCurlyOnNewLine, Boolean closeCurlyOnNewLine, Boolean preserveOriginalWhitespace, Boolean keepRedundantApiCalls, Boolean avoidUsingStatic) in C:\RoslynQuoter\src\QuoterServiceOld\Controllers\QuoterController.cs:line 37
When trying to use a C# 7.1 feature, like default literal, RoslynQuoter fails with an exception. I think it should set language version to latest, to avoid this kind of problem.
As an example, this code:
Produces this exception: