Skip to content

Instantly share code, notes, and snippets.

View richlander's full-sized avatar

Rich Lander richlander

View GitHub Profile
@richlander
richlander / ClimateControl.csproj
Created October 11, 2021 15:16
Extended properties example
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@richlander
richlander / Program.cs
Last active October 21, 2021 15:52
Record struct example
Battery battery = new("CR2032", 0.235, 100);
WriteLine(battery);
while (battery.RemainingCapacityPercentage > 0)
{
battery.RemainingCapacityPercentage--;
}
WriteLine(battery);
namespace XUnitTestProject
{
using Xunit;
public static class SwitchStatementMapper
{
// Don't judge me, it's only for educational purposes :)
public static bool Map(string str) => str switch
{
"true" => true,
@richlander
richlander / modernizing-csharp9.md
Last active April 26, 2024 17:14
Modernizing a codebase for C# 9

Modernizing a codebase for C# 9

There are lots of cases that you can improve. The examples use nullable reference types, but only the WhenNotNull example requires it.

Use the property pattern to replace IsNullorEmpty

Consider adopting the new property pattern, wherever you use IsNullOrEmpty.

string? hello = "hello world";
@richlander
richlander / Program.cs
Last active October 12, 2023 17:02
Get Weather Forecast -- with records
using System;
using System.Net.Http;
using System.Net.Http.Json;
string serviceURL = "https://localhost:5001/WeatherForecast";
HttpClient client = new();
Forecast[] forecasts = await client.GetFromJsonAsync<Forecast[]>(serviceURL);
foreach(Forecast forecast in forecasts)
{
@richlander
richlander / collect-dotnet-framework-logs.md
Last active February 17, 2020 20:51
Troubleshooting installing the .NET Framework

Troubleshooting installing the .NET Framework

You may be having trouble installing the .NET Framework. This document describes a set of steps you can take that may help you get it installed or help you undertstand why it isn't working.

Validate your Windows version

Not all .NET Framework versions are supported on all Windows versions. .NET Framework 4.8 is the latest version of the .NET Framework. We recommend you install it if you can. The following list describes which .NET Framework versions are supported on various Windows versions.

  • .NET Framework 4.8 is supported on Windows 7 and later, and Windows Server 2008 R2 and later
  • .NET Framework 4.8 is not supported on Windows XP, Windows Vista, Windows 8.0, or Windows Server 2003.
@richlander
richlander / RetrievingDockerImageSizes.md
Last active January 3, 2020 18:04 — forked from MichaelSimons/RetrievingDockerImageSizes.md
Retrieving Docker Image Sizes

Retrieving Docker Image Sizes

There are two metrics that are important to consider when discussing the size of Docker images.

  1. Compressed size - This is often referred to as the wire size. This affects how fast/slow images can be pulled from a registry. This impacts the first run experience on machines where images are not cached.
  2. Uncompressed size - This is often referred to as the size on disk. This affects how much local storage is required to support your Docker workloads.

The example commands shown below will work on Windows, MacOS, and Linux.

How to Measure the Compressed Size

@richlander
richlander / share-the-love.md
Last active July 20, 2021 16:53
.NET Core 3.0 -- Post Launch Blog Posts

.NET Core 3.0 -- Post Launch Blog Posts

We launched .NET Core 3.0! Go team! The super official blog post covered a lot of features, but none of them at depth. Many people will want to learn more about specific scenarios at features at much greater depth, with more guidance and better code samples.

The following is a list of proposed posts (with descriptive but prelimary titles) for us to write and publish during the rest of 2019.

Note: This tweet also has feedback.

Getting Started

@richlander
richlander / sdk-size-improvements.md
Created July 23, 2019 16:32
.NET Core 3.0 SDK Size Improvements

.NET Core 3.0 SDK Size Improvements

The .NET Core SDK is significantly smaller with .NET Core 3.0. The primary reason is that we changed the way we construct the SDK, by moving to purpose-built “packs” of various kinds (reference assemblies, frameworks, templates). In previous versions (including .NET Core 2.2), we constructed the SDK from NuGet packages, which included many artifacts that were not required and wasted a lot of space.

The following sections demonstrate the size improvements for Windows, Linux and macOS, including container delivery. They detail the process and commands that were used to determine the product sizes, enabling you to reproduce the same results in your own environment. To keep thing simple, zips and tar balls were downloaded from dotnet/core-sdk as opposed to the official installers.

Some readers will be shocked on how large the .NET Core 2.2 installer directory grows when the NuGetFallback archive is expanded to the NuGetFallBackFolder. W