Skip to content

Instantly share code, notes, and snippets.

View jmarolf's full-sized avatar

Jonathon Marolf jmarolf

View GitHub Profile
@jmarolf
jmarolf / gist:2325f55a12f2e1c48aa7
Created March 27, 2015 22:52
Adding reference and modifying document
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
namespace ConsoleApplication11
{
class Program
{
@jmarolf
jmarolf / gist:4b55afdd9a4c5269580c
Created April 4, 2015 22:46
Get parse errors from string.
using System;
using System.Collections;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
class Program
{
static void Main(string[] args)
{
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var list = new List<int>();
list.Where(x => x % 2 == 0).OrderByDescending(x => x)
.Select(x => x);
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var list = new List<int>();
list.Where(x => x % 2 == 0)
.OrderByDescending(x => x)
@jmarolf
jmarolf / DiagnosticVerifier.Helper.cs
Last active August 29, 2015 14:21
Change default severity
var compilation = project.GetCompilationAsync().Result;
var specificDiagnosticOptions = new[] { new KeyValuePair<string, ReportDiagnostic>(NotReportedByDefaultAnalyzer.DiagnosticId, ReportDiagnostic.Warn) };
var options = new CSharpCompilationOptions(outputKind: OutputKind.DynamicallyLinkedLibrary, specificDiagnosticOptions: specificDiagnosticOptions);
var compilationWithOptions = compilation.WithOptions(options);
var compilationWithAnalyzers = compilationWithOptions.WithAnalyzers(ImmutableArray.Create(analyzer));
var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using static Microsoft.CodeAnalysis.Diagnostic;
namespace Analyzer1 {
[DiagnosticAnalyzer(LanguageNames.CSharp)]
@jmarolf
jmarolf / editorconfig.md
Last active September 26, 2023 12:55
List of all options and how they may be implemented in editorconfig

Advanced

editorconfig name possible values
dotnet_sort_system_directives_first true , false

Indentation Options

editorconfig name possible values
csharp_indent_block_contents true , false
csharp_indent_braces true , false

Advanced

editorconfig name possible values
dotnet_sort_system_directives_first true , false

Indentation Options

editorconfig name possible values
csharp_indent_block_contents true , false
csharp_indent_braces true , false
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
namespace GetTypeName
{
class Program
{
@jmarolf
jmarolf / ConvertStringToSingleLine.cs
Created November 2, 2017 01:21
ConvertStringToSingleLine.cs
var a = "\n"; // token.ValueText.Contains("\n") == true
var b = @"\n"; // token.ValueText.Contains("\n") == false
var c = @"
"; // token.ValueText.Contains("\n") == true
var d = $@"\n";// token.ValueText.Contains("\n") == false
var e = $@"
"; // token.ValueText.Contains("\n") == false