This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tests | |
open System | |
open Xunit | |
open FsUnit.Xunit | |
let f x = | |
if true then (None,[]) | |
else | |
(Some x,[]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Foo | |
{ | |
public int Value { get; set; } | |
public override string ToString() | |
{ | |
return $"{{{nameof(Value)}={Value}}}"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Foo | |
{ | |
public int Value { get; set; } | |
public override string ToString() | |
{ | |
return $"{{{nameof(Value)}={Value.ToString()}}}"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using System; | |
namespace TestEnumSerialization | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Union<TOne, TOther> | |
{ | |
private readonly TOne _toneValue; | |
private readonly TOther _totherValue; | |
public Union(TOne value) => _toneValue = value; | |
public Union(TOther value) => _totherValue = value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int? a = 1; | |
int? b = null; | |
bool ba = a.HasValue; // true | |
bool bb = b.HasValue; // false | |
int c = b.Value + 1; // throws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Union<TOne, TOther> | |
{ | |
private readonly TOne _toneValue; | |
private readonly TOther _totherValue; | |
private readonly UnionType _type; | |
public Union(TOne value) | |
{ | |
_toneValue = value; | |
_type = UnionType.TOne; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Union<int, None> a = new Union<int, None>(1); | |
Union<int, None> b = new Union<int, None>(new None()); | |
// Here we are saying: | |
// if a (or b) contains an int, add 1 to the value and return the result | |
// if a (or b) contains None, just return 0 as a default value | |
var c = a.Match(v => v + 1, _ => 0); // this is 2 | |
var d = b.Match(v => v + 1, _ => 0); // this is 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
public bool IsPaid { get; set; } | |
private List<OrderItem> _items; | |
public List<OrderItem> GetItems() => new List<OrderItem>(_items); | |
public void Add(OrderItem item) | |
{ | |
if (IsPaid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
private List<OrderItem> _items; | |
public List<OrderItem> GetItems() => new List<OrderItem>(_items); | |
public void Add(OrderItem item) | |
{ | |
_items.Add(item); | |
} |
OlderNewer