Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Last active December 17, 2015 21:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akimboyko/5675582 to your computer and use it in GitHub Desktop.
Save akimboyko/5675582 to your computer and use it in GitHub Desktop.
Search for `return null;` `yield return null;`, `return default(object);` and equivalents from ScriptCs/LinqPAD
  • Install Chocolatey
  • Reopen console application (for example cmd.exe) to update %PATH% and other environment variables
  • Install ScriptCs using chocolatey
  • Install dependencies using scriptcs -install -pre
  • Edit solutionPath const to point to solution
  • Run scriptcs .\SearchForReturnNulls.csx
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Roslyn" version="1.2.20906.2" targetFramework="net45" />
<package id="Roslyn.Compilers" version="1.2.20906.2" targetFramework="net45" />
<package id="Roslyn.Compilers.Common" version="1.2.20906.2" targetFramework="net45" />
<package id="Roslyn.Compilers.CSharp" version="1.2.20906.2" targetFramework="net45" />
<package id="Roslyn.Services.Common" version="1.2.20906.2" targetFramework="net45" />
<package id="Roslyn.Services.CSharp" version="1.2.20906.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="5.0.5" targetFramework="net45" />
<package id="AfterProgramming" version="0.0.2-alpha" targetFramework="net45" />
</packages>
// scriptcs -install -pre — run to install dependencies
using System.Threading;
using System.Diagnostics;
using Roslyn.Compilers.CSharp;
using Roslyn.Compilers.Common;
using Newtonsoft.Json;
using AfterProgramming;
using AfterProgramming.Internal;
// change path to solution
const string solutionPath = @"D:\temp\nhibernate-core-master\src\NHibernate.Everything.sln";
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(5));
var cancellationToken = cancellationTokenSource.Token;
Console.WriteLine("Start introspection at {0}…", solutionPath);
var watch = Stopwatch.StartNew();
var results = new ReturnStatement()
.SearchForReturnNullStatements(solutionPath, cancellationToken);
watch.Stop();
Console.WriteLine(
JsonConvert.SerializeObject(
results.Take(10), Formatting.Indented));
Console.WriteLine("Finish introspection in {0} ms", watch.Elapsed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment