Skip to content

Instantly share code, notes, and snippets.

View SimonCropp's full-sized avatar

Simon Cropp SimonCropp

View GitHub Profile
<entry>
<record>678</record>
<time>2019/04/16 02:40:55.883</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.NullReferenceException: Object reference not set to an instance of an object.&#x000D;&#x000A;
at ShaneBlazek.DisableRegions.RegionLineTaggerProvider.CreateTagger[T](ITextView textView, ITextBuffer buffer)&#x000D;&#x000A;
at Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.InstantiateViewTagger(ITextView textView, Lazy`2 factory, ITextBuffer textBuffer, IList`1 newTaggers)&#x000D;&#x000A;---
End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;
@SimonCropp
SimonCropp / OpenSolution.cmd
Created December 3, 2019 05:09
Fork: Open in VS
cd %1
powershell -executionpolicy remotesigned -file c:\code\opensolution.ps1 -nologo
@SimonCropp
SimonCropp / Consider-not-using-namespaces.md
Last active January 18, 2020 18:30
Consider not using namespaces

Over the years C# has been criticised for being too verbose. This is especially common when compared to languages like Scala, FSharp, Erlang, Ruby and Javascript. There is no arguing that the syntactic constructs in these languages allow for a much terser coding style. However C# can be more succinct than people realize.

So with the idea that "less code is better code", what can be changed about how we code C#?

There are a few solutions, for now, I'm going to focus on:

Consider NOT using namespaces

This might sound crazy but bear with me.

var props = typeof(DateTimeFormatInfo).GetProperties();
var value = new DateTime(2012, 5, 28, 11, 35, 0);
var builder = new StringBuilder();
foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
{
builder.AppendLine(culture.DisplayName);
var info = culture.DateTimeFormat;
foreach (var prop in props)
{

The case for disabling GH Issues

Disclaimer: This is a personal perspective. The majority of OSS projects I contribute to are libraries and developer tooling. The side effect of this is that if a person is using one of these projects, they have the expertise to understand and modify the code of the project. Also many of the comments made are from my experience, your experience may vary.

The problem with GitHub Issues

Too generic

@SimonCropp
SimonCropp / Enabling_OSS_sustainability.md
Last active January 3, 2021 18:51
Enabling OSS sustainability

Add "requesting sponsorship" to package metadata

Package formats (nuget, npm etc) should be amended to add the concept of "this package is requesting sponsorship via ...". The "via..." part could be influence by the GitHub Funding.yml convention.

Surface "requesting sponsorship" in tooling

Once "requesting sponsorship" metadata is added, tooling can expose this in a variety of ways. For example:

@SimonCropp
SimonCropp / cs
Last active December 22, 2023 01:58
StringBuilder AsSpan
#if NET8_0_OR_GREATER
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "m_ChunkPrevious")]
private static extern ref StringBuilder? ChunkPrevious(StringBuilder builder);
static bool HasSingleChunk(this StringBuilder builder) =>
ChunkPrevious(builder) == null;
#endif
public static CharSpan AsSpan(this StringBuilder builder)
{