Skip to content

Instantly share code, notes, and snippets.

View jmarolf's full-sized avatar

Jonathon Marolf jmarolf

View GitHub Profile
`build.ps1 -build -sign -pack`:
- Build-Artifacts
- Run-MSBuild "Roslyn.sln" "/p:DeployExtension=false"
- Build-ExtraSignArtifacts
- Build-NuGetPackages
- Run-SignTool
- Build-InsertionItems
`build.ps1 -build`:
- Build-Artifacts
@jmarolf
jmarolf / CodeAnalysisApp1.csproj
Last active March 22, 2018 22:24
example standalone code analysis tool
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net471</TargetFramework>
<LangVersion>Latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Locator" Version="1.0.7-preview-ge60d679b53" />
public static void CopyFile(string from, string into) 
{
    using (var fromFile = File.Open(from, FileMode.Open, FileAccess.Read))
    using (var toFile = File.Open(into, FileMode.Create, FileAccess.Write))
    {
    // ... Perform actual file copy

    // Both FileStream objects are disposed at the end of the enclosing scope, 
    // in this case, the method declaration.
public static void CopyFile(string from, string into) 
{
    using (var fromFile = File.Open(from, FileMode.Open, FileAccess.Read))
    using (var toFile = File.Open(into, FileMode.Create, FileAccess.Write))
    {
    // ... Perform actual file copy

    // Both FileStream objects are disposed at the end of the enclosing scope, 
    // in this case, the method declaration.
@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
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
namespace GetTypeName
{
class Program
{

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
@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
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 / 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;