Skip to content

Instantly share code, notes, and snippets.

View Schandlich's full-sized avatar

Luke Sigler Schandlich

View GitHub Profile
@Schandlich
Schandlich / CodeFixProvider.cs
Last active August 29, 2015 14:06
Rosyln Interface Name Checker
[ExportCodeFixProvider(DiagnosticAnalyzer.DiagnosticId, LanguageNames.CSharp)]
internal class CodeFixProvider : ICodeFixProvider
{
public IEnumerable<string> GetFixableDiagnosticIds()
{
return new[] { DiagnosticAnalyzer.DiagnosticId };
}
public async Task<IEnumerable<CodeAction>> GetFixesAsync(Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
{
@Schandlich
Schandlich / DiagnosticAnalyzer
Created June 4, 2014 21:36
Roslyn EndOfFile
[DiagnosticAnalyzer]
[ExportDiagnosticAnalyzer(DiagnosticId, LanguageNames.CSharp)]
public class DiagnosticAnalyzer : ISyntaxTreeAnalyzer
{
internal const string DiagnosticId = "EndOfFile";
internal const string Description = "No blank lines at the end of the file please.";
internal const string MessageFormat = "No blank lines at the end of the file please.";
internal const string Category = "Naming";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Description, MessageFormat, Category, DiagnosticSeverity.Warning);
@Schandlich
Schandlich / Program.cs
Created May 23, 2014 17:09
C# Parallel Interview Question
class Program
{
static void Main(string[] args)
{
Random rand = new Random();
var currentInt = 0;
int[] tasks = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; // Should have used F#.
Parallel.ForEach(tasks, (x) =>
@Schandlich
Schandlich / CodeFixProvider
Last active August 29, 2015 14:01
Async Method Name Checker
[ExportCodeFixProvider(DiagnosticAnalyzer.DiagnosticId, LanguageNames.CSharp)]
internal class CodeFixProvider : ICodeFixProvider
{
public IEnumerable<string> GetFixableDiagnosticIds()
{
return new[] { DiagnosticAnalyzer.DiagnosticId };
}
public async Task<IEnumerable<CodeAction>> GetFixesAsync(Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
{
@Schandlich
Schandlich / AutoHotkey.ahk
Created May 6, 2014 22:41
AHK Create guid, copy to clipboard, and paste.
^!g::
TypeLib := ComObjCreate("Scriptlet.TypeLib")
NewGUID := TypeLib.Guid
clipboard = %NewGUID%
Send ^v
[DiagnosticAnalyzer]
[ExportDiagnosticAnalyzer(DiagnosticId, LanguageNames.CSharp)]
public class DiagnosticAnalyzer : ISyntaxNodeAnalyzer<SyntaxKind>
{
internal const string DiagnosticId = "DoNotThrowCaughtException";
internal const string Description = "Do not throw back a caught exception like this.";
internal const string MessageFormat = "Really? REALLY?!";
internal const string Category = "Usage";
internal static DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Description, MessageFormat, Category, DiagnosticSeverity.Warning);
@Schandlich
Schandlich / gist:9353340
Created March 4, 2014 19:06
Potential Changes
var stereotype = StereotypeBuilder.Build()
.WithStereotypes(c =>
{
c.RegisterStereotype<Product>(s => s.RegisterGenerator<Guid>((existingValue) => Guid.NewGuid())
.RegisterGenerator<int>((existingValue) => StandardGenerators.Current.GenerateInt()));
});
var list = new List<Product>();
for (int i = 0; i < 2000; i++)