Skip to content

Instantly share code, notes, and snippets.

View VincentH-Net's full-sized avatar
🔥
Innovating full stack development with C#

Vincent Hoogendoorn VincentH-Net

🔥
Innovating full stack development with C#
View GitHub Profile
@VincentH-Net
VincentH-Net / Extensions.cs
Created April 9, 2024 18:03
ASP.NET Core Minimal API's Endpoints registration helper
// Endpoints registration helper
// Enables DI for a group of endpoints to reduce init code and repeating parameters across endpoints
// Usage in e.g. Program.cs:
app.RegisterEndpoints(
typeof(CatalogEndpoints),
typeof(BasketsEndpoints)
);
@VincentH-Net
VincentH-Net / UseOpenApiInFlutter.md
Last active May 25, 2023 10:54
Use OpenApi in Flutter

To generate an API client in Dart from an OpenApi.json file, and use it in Flutter, follow these steps:

Related: see this gist for how to generate an OpenApi.json file on build from an ASP.NET 8 Minimal API project

  1. Create a new Flutter 3.10 (or later) Application project in Visual Studio Code: steps
  2. Add the openapi_generator package to your project. Follow below steps instead of the instructions at pub.dev (at the time of writing they were out of date):
    • Include openapi_generator_annotationsin the dependencies section of your pubspec.yaml file :
      dependencies:
        openapi_generator_annotations: ^4.10.0
@VincentH-Net
VincentH-Net / GenerateOpenApiOnBuildFromNet8MinimalApi.md
Last active March 30, 2024 17:49
Generate OpenApi.json on build from ASP.NET 8 Minimal API

To generate OpenApi.json on build from an ASP.NET 8 Minimal API, follow these steps:

  1. In Visual Studio for Windows 17.7.0 or later, create a new ASP.NET Core API project

  2. Follow these instructions to install Swashbuckle.AspNetCore.Cli as a local dotnet tool in your project

  3. Add these NuGet packages (or later versions) to the project:

  <ItemGroup>
  	<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.4.23260.4" />
@VincentH-Net
VincentH-Net / .editorconfig
Created July 4, 2022 17:21
.editorconfig naming rule for NO underscore prefix on private fields
# Start of NO underscore prefix on private fields
# Define the 'private_fields' symbol group:
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
# Define the 'notunderscored' naming style
dotnet_naming_style.notunderscored.capitalization = camel_case
dotnet_naming_style.notunderscored.required_prefix =
# Define the 'private_fields_notunderscored' naming rule
@VincentH-Net
VincentH-Net / RegistrationCodePage.cs
Last active April 4, 2022 18:47
C# language proposal examples for UI markup #CSharpForMarkup
// C# vNext markup friendly
enum Row { Icon, Prompt, Header, Entry }
void Build() => Content = new Grid
{
RowDefinitions = Rows.Define(
(Icon , Auto),
(Prompt, Auto),
(Header, 50 ),
(Entry , Auto)
@VincentH-Net
VincentH-Net / WhiteIBeam1.cape
Last active October 2, 2017 10:12
White IBeam cursor to fix mouse visibility in Visual Studio for Mac text editor on dark backgrounds. To use, first install https://github.com/alexzielenski/Mousecape/releases/tag/0.0.5 and then doubleclick .cape file (icon source: https://github.com/egold/better-xcode-ibeam-cursor)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Author</key>
<string>Vincent Hoogendoorn</string>
<key>CapeName</key>
<string>WhiteIBeam</string>
<key>CapeVersion</key>
<real>1</real>
@VincentH-Net
VincentH-Net / SharpSvgImageSource.cs
Last active March 20, 2017 15:33
Temporary fix for unsharp SVG's in FFImageLoading
using FFImageLoading;
using FFImageLoading.Config;
using FFImageLoading.DataResolvers;
using FFImageLoading.Forms;
using FFImageLoading.Svg.Platform;
using FFImageLoading.Work;
using SkiaSharp;
using System;
using System.IO;
using System.Reflection;
@VincentH-Net
VincentH-Net / ApiModels2ViewModels.cs
Last active July 13, 2016 13:26
Backend For FrontEnd API for Xamarin Apps
using System.Threading.Tasks;
using PropertyChanged;
/// <summary>
/// See "Consuming the BFF API" in http://vincenth.net/blog/archive/2016/07/13/building-bff-backend-for-frontend-apis-for-xamarin-mobile-apps.aspx
/// </summary>
namespace MyApp.ApiModels
{
[ImplementPropertyChanged] // This will make all properties in all partial Contact classes data-bindable
public partial class Contact : ViewModelBase
@VincentH-Net
VincentH-Net / FormsBinding.sketchcs.cs
Last active March 21, 2016 18:09
Xamarin Forms Sketch demonstrating data binding (without strings, to nested objects, to unlimited number of fields) and common app/sketch code. Note: remove the .cs from the file name, it is only there to make GitHub format it as C#
using Xamarin.Forms;
// Additional guidance: see http://vincenth.net/blog/archive/2014/11/27/how-to-share-xamarin-forms-data-binding-code-across-xamarin-sketches-and-apps-without-using-strings.aspx
// NOTE: Once support for creating classes is added to Xamarin Sketches,
// there is no need for this Tuple + enum + BindName + regular expression workaround;
// you can then simply create design data classes in the Sketch and bind to that using
// the same syntax in both projects and sketches, e.g.:
// SetBinding(..., (Person boundPerson) => boundPerson.Name)
// BindName helper function for use with binding to design data in Sketches.
@VincentH-Net
VincentH-Net / KeyboardDismissGestureRecognizer.cs
Created January 10, 2014 13:52
KeyboardDismissGestureRecognizer automatically dismisses the onscreen keyboard in Xamarin.iOS when a user taps outside an editable view. Simply add a KeyboardDismissGestureRecognizer to your application's main window in FinishedLaunching.
/// <summary>
/// To automatically dismiss the onscreen keyboard in iOS when a user taps outside an editable view,
/// add a KeyboardDismissGestureRecognizer to your application's main window in FinishedLaunching, e.g.:
/// Window.AddGestureRecognizer(new KeyboardDismissGestureRecognizer());
/// </summary>
public class KeyboardDismissGestureRecognizer : UITapGestureRecognizer
{
public KeyboardDismissGestureRecognizer() : base(() => { }) { CancelsTouchesInView = false; }
public override void TouchesBegan(NSSet touches, UIEvent evt)