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 System; | |
using System.Linq; | |
using System.Text.Json; | |
using System.Text.Json.Serialization; | |
namespace Infrastructure | |
{ | |
public static class JsonSerializationExtensions | |
{ | |
public static readonly JsonSerializerOptions SnakeCaseSerializerOptions = new() |
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 System.Text.Json; | |
using System.Text.Json.Serialization; | |
namespace Infrastructure | |
{ | |
public static class JsonSerializationExtensions | |
{ | |
public static JsonSerializerOptions DefaultSerializerOptions = new JsonSerializerOptions | |
{ | |
WriteIndented = false, |
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
void Main() | |
{ | |
// 1: NOT QUITE IMMUTABLE | |
var mutablePerson = new MutablePerson(); | |
mutablePerson.Name = "Clint"; | |
mutablePerson.Age = 41; | |
mutablePerson.Dump("Initial Values"); | |
mutablePerson.Name = "Jerry"; |
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
internal static class HttpClientExtensions | |
{ | |
public static Task<HttpResponseMessage> PostAsJsonAsync<T>(this HttpClient client, string uri, T content, string messageId = null) | |
=> SendAsJsonAsync<T>(client, HttpMethod.Post, uri, content, messageId); | |
public static Task<HttpResponseMessage> PutAsJsonAsync<T>(this HttpClient client, string uri, T content) | |
=> SendAsJsonAsync<T>(client, HttpMethod.Put, uri, content, null); | |
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, string uri) | |
{ |
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
// https://docs.microsoft.com/en-us/dotnet/api/system.timezoneinfo.createcustomtimezone?view=netframework-4.7.2 | |
void Main() | |
{ | |
TimeZoneInfo | |
.ConvertTime( | |
DateTimeOffset.Parse("2019-02-18 19:51 -05:00", CultureInfo.InvariantCulture), | |
TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time")).Dump("Sydney Time"); | |
TimeZoneInfo | |
.ConvertTime( | |
DateTimeOffset.Parse("2019-02-18 19:51 -05:00", CultureInfo.InvariantCulture), |
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
// Great explanation on Stackoverflow: https://stackoverflow.com/a/1710395/190476 | |
void Main() | |
{ | |
Predicate<Person> personWithId1 = person => person.Id == 1; | |
Predicate<Person> personsOver30 = person => person.Age > 30; | |
var persons = new List<Person> | |
{ | |
new Person { |
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 Program | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(new DateTime(2019,2,2, 0,0,0), TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time"))); | |
Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(new DateTime(2019,2,2, 23,59,59), TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time"))); | |
Console.WriteLine(new DateTime( | |
2019, | |
2, | |
2, |
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
# Docker container: gittools/gitversion-dotnetcore:linux-4.0.1 | |
# NugetPackageVersion is a variable defined for the Azure DevOps pipeline | |
NEXTVERSION="$(docker run --rm -v "$(pwd):$BUILD_SOURCESDIRECTORY/path-to-repo" gittools/gitversion-dotnetcore:linux-4.0.1 $BUILD_SOURCESDIRECTORY/path-to-repo /output json /showvariable MajorMinorPatch)" | |
# the following command sets the pipeline variable's value to NEXTVERSION | |
echo "##vso[task.setvariable variable=NugetPackageVersion]$NEXTVERSION" |
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
/* | |
* Use an approach similar to ASP.NET core for generic host in a console application | |
*/ | |
public interface IStartup | |
{ | |
void ConfigureServices( | |
HostBuilderContext hostBuilderContext, | |
IServiceCollection serviceCollection); |
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 System; | |
using System.Globalization; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Converters; | |
public class UtcSydneyDateFormatConverter : IsoDateTimeConverter | |
{ | |
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | |
{ | |
DateTimeStyles = DateTimeStyles.AdjustToUniversal; |
NewerOlder