Skip to content

Instantly share code, notes, and snippets.

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

Christian Findlay MelbourneDeveloper

🏠
Working from home
View GitHub Profile
@MelbourneDeveloper
MelbourneDeveloper / Program.cs
Created February 13, 2021 08:16
Nullable Reference Types Minimal Console App Sample
#nullable enable
using Sample;
using System;
var testRecord = new TestRecord("Hi", null);
Console.WriteLine(testRecord.NotNullableProperty);
namespace Sample
{
@MelbourneDeveloper
MelbourneDeveloper / NullGuardExample.cs
Created February 13, 2021 08:37
Null Guard Example
#nullable enable
using System;
namespace Sample
{
public class NullGuardExample
{
public string NotNullableProperty { get; }
public string? NullableProperty { get; }
@MelbourneDeveloper
MelbourneDeveloper / Program.cs
Last active February 14, 2021 01:15
Null Object Example
#nullable enable
namespace NullObjectExample
{
class Program
{
static void Main()
{
var someService = new SomeService();
}
@MelbourneDeveloper
MelbourneDeveloper / Observer.cs
Created February 21, 2021 00:43
Observer with Null Object Pattern
internal class Observer<T> : IObserver<T>
{
static Action<Exception> onError = ((e) => { });
static Action onCompleted = (() => { });
private readonly Action<T> _onNext;
private readonly Action<Exception> _onError;
private readonly Action _onCompleted;
public Observer(
@MelbourneDeveloper
MelbourneDeveloper / LogCheckExtensions.cs
Last active April 28, 2021 11:50
ILogger Verification with Moq
using Microsoft.Extensions.Logging;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
// More detailed samples here:
// https://github.com/MelbourneDeveloper/RestClient.Net/blob/79cca66e02f83a1043c44f215d374139f40f8c12/src/RestClient.Net.UnitTests/UnitTests.cs#L758
@MelbourneDeveloper
MelbourneDeveloper / StringValidator.cs
Created April 28, 2021 22:32
String Validator Class
public class StringValidator
{
public string InputString { get; }
public StringValidator(string inputString)
{
if (string.IsNullOrEmpty(inputString)) throw new ArgumentNullException(nameof(inputString));
InputString = inputString;
}
@MelbourneDeveloper
MelbourneDeveloper / StringValidator.cs
Created April 28, 2021 22:34
String Validator Record
public record StringValidator(string InputString);
@MelbourneDeveloper
MelbourneDeveloper / StringValidator.cs
Last active April 28, 2021 23:12
String Validator Record
public record StringValidator
{
public string InputString { get; }
public StringValidator(string inputString)
{
if (string.IsNullOrEmpty(inputString)) throw new ArgumentNullException(nameof(inputString));
InputString = inputString;
}
@MelbourneDeveloper
MelbourneDeveloper / StringValidator.cs
Created April 29, 2021 23:36
String Validator Full
using System;
namespace ConsoleApp25
{
class Program
{
static void Main(string[] args)
{
//This throws an exception from the constructor
//var stringValidator = new StringValidator(null);