Skip to content

Instantly share code, notes, and snippets.

@arphox
arphox / DependencyRegistrationChecker.cs
Last active September 9, 2022 17:07
Azure Functions DependencyRegistrationChecker
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Xunit;
namespace MyUnitTestProject;
@arphox
arphox / ReSharper-live-template-new-nunit-test-method-argexnull.md
Created November 22, 2021 06:36
ReSharper live template to create an NUnit test method which tests that the given code throws `ArgumentNullException`

Use the .DotSettings file to import.

Preview:

[Test] 
public void If$ParameterName$IsNull_ThrowsException() 
{ 
    // Arrange & Act 
 Action act = () => $END$;
@arphox
arphox / ReSharper-surround-template-action_act.md
Created November 22, 2021 06:32
ReSharper surround template to wrap something with `Action act = () => { }`.

Use the .DotSettings file to import.

Preview:

Action act = () => $SELECTION$$END$
@arphox
arphox / ReSharper-live-template-new-nunit-test-method.md
Created November 22, 2021 06:28
ReSharper live template to create an NUnit test method

Use the .DotSettings file to import.

Preview:

[Test] 
public void $METHOD$() 
{ 
    // Arrange 
    $END$ 
@arphox
arphox / ReSharper-file-template-new-nunit-test-class.md
Last active November 22, 2021 06:33
ReSharper file template to create an NUnit test class

Use the .DotSettings file to import.

Preview:

using NUnit.Framework; 

namespace $NAMESPACE$ 
{ 

 ///  
@arphox
arphox / PR_best_practices.md
Last active February 15, 2024 16:35
Pull request best practices

Pull request best practices

A meta-analysis by Károly Ozsvárt

Key takeaways

  • Keep PRs small [1] [2] [3] [4] [5] [7]
  • Break down large pull requests into smaller ones [1] [5]
  • Have a good title [1] [4] [9]
  • Have a good description [1] [4] [9]
  • Reviewing PRs is hard [4] [6]
  • Have good commit messages [4] [7]
@arphox
arphox / Enum.HasFlag performance loss.cs
Created May 15, 2019 06:57
Enum.HasFlag performance loss
// Based on https://stackoverflow.com/q/7368652/4215389
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace app
{
public class Program
@arphox
arphox / IsSet2.cs
Created May 15, 2019 06:39
Generic attempt for IsSet
public static bool IsSet2<T>(this T self, T flag) where T : Enum
{
return (self & flag) == flag;
}
@arphox
arphox / MyExtensions.cs
Created May 15, 2019 06:33
Efficient enum HasFlag implementation
public static class MyExtensions
{
public static bool IsSet(this Color self, Color flag)
{
return (self & flag) == flag;
}
}
@arphox
arphox / InternalHasFlag.cpp
Last active November 22, 2021 06:22
InternalHasFlag C++ implementation
// preform (this & flags) != flags
FCIMPL2(FC_BOOL_RET, ReflectionEnum::InternalHasFlag, Object *pRefThis, Object* pRefFlags)
{
FCALL_CONTRACT;
VALIDATEOBJECT(pRefThis);
BOOL cmp = false;
_ASSERTE(pRefFlags != NULL); // Enum.cs would have thrown ArgumentNullException before calling into InternalHasFlag