Skip to content

Instantly share code, notes, and snippets.

View aalmada's full-sized avatar
🏠
Working from home

Antão Almada aalmada

🏠
Working from home
View GitHub Profile
<ItemGroup>
<Compile Update="TestData\**\*.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
</ItemGroup>
public class AssignmentBoxingTests : DiagnosticVerifier
{
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() =>
new AssignmentBoxingAnalyzer();
[Theory]
[InlineData("TestData/HLQ001/NoDiagnostic/FieldDeclaration.cs")]
[InlineData("TestData/HLQ001/NoDiagnostic/FieldDeclaration.Async.cs")]
[InlineData("TestData/HLQ001/NoDiagnostic/PropertyDeclaration.cs")]
[InlineData("TestData/HLQ001/NoDiagnostic/PropertyDeclaration.Async.cs")]
[TestMethod]
public void TestMethod2()
{
var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace NetFabric.Hyperlinq
{
public static class Result
{
[Pure]
public static DelayedOk<TOk> Ok<TOk>(TOk ok)
=> new DelayedOk<TOk>(ok);
using System;
using System.Diagnostics.Contracts;
namespace NetFabric.Hyperlinq
{
public static class Option
{
[Pure]
public static NoneOption None { get; } = new NoneOption();
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace HeadTail
{
[MemoryDiagnoser]
@aalmada
aalmada / Singleton.cs
Last active August 30, 2019 10:45
Singleton base MonoBehaviour implementation. Based on the one on Unity Community Wiki but with fixes and using modern C#.
using UnityEngine;
/// <summary>
/// Inherit from this base class to create a singleton.
/// e.g. public class MyClassName : Singleton<MyClassName> {}
/// </summary>
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
// Check to see if we're about to be destroyed.
static bool shuttingDown = false;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using System;
namespace Benchmarks
{
[MemoryDiagnoser]
[MarkdownExporterAttribute.GitHub]
public class ValueEnumerableBenchmarks2
{
BenchmarkDotNet=v0.11.4, OS=macOS Mojave 10.14.4 (18E226) [Darwin 18.5.0]
Intel Core i5-7360U CPU 2.30GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores
.NET Core SDK=3.0.100-preview4-011223
  [Host]     : .NET Core 2.1.6 (CoreCLR 4.6.27019.06, CoreFX 4.6.27019.05), 64bit RyuJIT
  DefaultJob : .NET Core 2.1.6 (CoreCLR 4.6.27019.06, CoreFX 4.6.27019.05), 64bit RyuJIT

@aalmada
aalmada / TypeExtensions.GetFriendlyName.cs
Created January 4, 2019 14:14
An extension-method for System.Type that returns its human-readable name.
public static partial class TypeExtensions
{
public static string GetFriendlyName(this Type type)
{
if (!type.IsGenericType)
return type.FullName;
var name = type.FullName.Substring(0, type.FullName.IndexOf('`'));
var fullName = new StringBuilder(name);
fullName.Append("<");