Permalink
Browse files

Merge pull request #42 from andymac4182/linqpad

Add support for generating a LINQPad file
  • Loading branch information...
KirillOsenkov committed Jun 28, 2018
2 parents 3a7df64 + 512d1e4 commit 5e066de5ac9b5094a5b3ee9130e35589d574f95a
@@ -11,14 +11,15 @@ namespace QuoterService.Controllers
public class QuoterController : Controller
{
[HttpGet]
public string Get(
public IActionResult Get(
string sourceText,
NodeKind nodeKind = NodeKind.CompilationUnit,
bool openCurlyOnNewLine = false,
bool closeCurlyOnNewLine = false,
bool preserveOriginalWhitespace = false,
bool keepRedundantApiCalls = false,
bool avoidUsingStatic = false)
bool avoidUsingStatic = false,
bool generateLINQPad = false)
{
string prefix = null;
@@ -54,14 +55,33 @@ public class QuoterController : Controller
}
}
if (generateLINQPad)
{
var linqpadFile = $@"<Query Kind=""Expression"">
<NuGetReference>Microsoft.CodeAnalysis.Compilers</NuGetReference>
<NuGetReference>Microsoft.CodeAnalysis.CSharp</NuGetReference>
<Namespace>static Microsoft.CodeAnalysis.CSharp.SyntaxFactory</Namespace>
<Namespace>Microsoft.CodeAnalysis.CSharp.Syntax</Namespace>
<Namespace>Microsoft.CodeAnalysis.CSharp</Namespace>
<Namespace>Microsoft.CodeAnalysis</Namespace>
</Query>
{responseText}
";
var responseBytes = Encoding.UTF8.GetBytes(linqpadFile);
return File(responseBytes, "application/octet-stream", "Quoter.linq");
}
responseText = HttpUtility.HtmlEncode(responseText);
if (prefix != null)
{
responseText = "<div class=\"error\"><p>" + prefix + "</p><p>" + responseText + "</p><p><br/>P.S. Sorry!</p></div>";
}
return responseText;
return Ok(responseText);
}
}
}
@@ -58,6 +58,9 @@
<div>
<button id="submitButton" type="button" onclick="onSubmitClick();">Get Roslyn API calls to generate this code!</button> &nbsp;<span id="working" style="display: none">Working...</span>
</div>
<div>
<button id="LINQPadButton" type="button" onclick="onSubmitLINQPad();">Get Roslyn API calls to generate this code as LINQPad file!</button>
</div>
</div>
<div id="outputDiv" xml:space="preserve">
CompilationUnit()
@@ -1,7 +1,7 @@
function onPageLoad() {
}
function onSubmitClick() {
function generateQuery() {
var nodeKind = document.getElementById("nodeKind").value;
var openCurlyOnNewLine = getCheckboxValue("openCurlyOnNewLine");
var closeCurlyOnNewLine = getCheckboxValue("closeCurlyOnNewLine");
@@ -32,9 +32,23 @@ function onSubmitClick() {
query = query + "&avoidUsingStatic=true";
}
return query;
}
function onSubmitClick() {
var query = generateQuery();
getUrl(query, loadResults);
}
function onSubmitLINQPad() {
var query = generateQuery();
query = query + "&generateLINQPad=true";
window.location = query;
}
function getCheckboxValue(id) {
return document.getElementById(id).checked;
}

0 comments on commit 5e066de

Please sign in to comment.