Skip to content

Instantly share code, notes, and snippets.

@Yaevh
Yaevh / SerializeModelStatePageFilter.cs
Last active February 1, 2023 11:34
Serializing ModelState in TempData to persist in on redirect in POST-REDIRECT-GET pattern in ASP.NET Core 3.1 Razor Pages
// inspired by https://andrewlock.net/post-redirect-get-using-tempdata-in-asp-net-core/
// usage: in Startup.ConfigureServices() add `services.AddRazorPages().AddMvcOptions(options => options.Filters.Add<SerializeModelStatePageFilter>());`
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using System;
using System.Collections.Generic;
@adamkewley
adamkewley / SerialPortExtensions.cs
Created December 4, 2015 20:33
Extension methods to make System.IO.Ports.SerialPort easier to use with .NET 4.5 async workflows (Does not support timeouts)
using System.IO.Ports;
namespace AsyncExtensions {
public static class SerialPortExtensions
{
/// <summary>
/// Read a line from the SerialPort asynchronously
/// </summary>
/// <param name="serialPort">The port to read data from</param>
/// <returns>A line read from the input</returns>