Skip to content

Instantly share code, notes, and snippets.

View ByteDev's full-sized avatar
:octocat:

ByteDev

:octocat:
View GitHub Profile
@ByteDev
ByteDev / DirectoryBuildprops-For-StyleCop.md
Last active February 15, 2022 08:20
Example Directory.Build.props for StyleCop
<Project>
  
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)ByteDev.Custom.ruleset</CodeAnalysisRuleSet>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)ByteDev.Custom.ruleset</CodeAnalysisRuleSet>
using System.Text.Json.Serialization;

// ...

public class AddressRequest
{
    [JsonPropertyName("addressId")]
    public int Id { get; set; }
public async Task<SearchCustomerResponse> SearchAsync(SearchCustomerRequest request, CancellationToken cancellationToken = default)
{
    // make the call to the API and handle the response
    // making sure to pass in the cancellationToken to any async method
}
public interface ICustomerApiClient
{
    Task<SearchCustomerResponse> SearchAsync(SearchCustomerRequest request, CancellationToken cancellationToken = default);
}

// ...

public class CustomerApiClient : ICustomerApiClient
{
{
  "errors": {
    "customer": [
      "The customer field is required.",
      "The customer field should be uppercase."
    ],
    "orders": [
      "The orders field is required."
 ]
{
  "message": "Resource not found." 
}
{
  "messages": [{
 "code": "2001",
using System;
using System.Text.Json;
using NUnit.Framework;

// ...

public class TestEntity
{
    [JsonPropertyName("datetime")]
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

// ...

public class UnixEpochTimeToDateTimeJsonConverter : JsonConverter<DateTime>
{
 public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;

// ...

[TestFixture]
public class EntityNotFoundExceptionTests