Skip to content

Instantly share code, notes, and snippets.

@VinceAvery
VinceAvery / CSharpClassWriter.cs
Last active November 13, 2018 20:34
Add attributes to CSHarp Classes
public class CSharpClassRewriter : CSharpSyntaxRewriter {
private readonly string _sourceCode;
private readonly Attribute _attributeToAdd;
public CSharpClassRewriter(
string sourceCode,
Attribute attributeToAdd = null) {
if (string.IsNullOrEmpty(sourceCode)) {
throw new ArgumentNullException(nameof(sourceCode));
@VinceAvery
VinceAvery / ISINValidator
Last active September 15, 2023 04:45
A validator to check a financial identifier called an ISIN, an International Securities Identification Number. It has the ability to both calculate the checksum and validate the complete ISIN, and also it is simple to understand, with as few methods as possible.
namespace ConsoleApplication.Validators {
public interface IIsinValidator {
bool IsChecksumCorrect(string dataWithChecksum, bool checkLastDigit);
}
public class IsinValidator : IIsinValidator {
public bool IsChecksumCorrect(string dataWithChecksum, bool checkLastDigit) {
try {
@VinceAvery
VinceAvery / JsonNetSerialization.fsx
Created March 16, 2017 16:18
Demonstrates how to change the shape of the Json for union tyes in F# when using the Json.NET serializer.
#load "Scripts\load-references-debug.fsx"
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
open Newtonsoft.Json.Linq
open System
// ***************** Domain *****************
type SingleCaseUnion = SingleCaseUnion of int