Skip to content

Instantly share code, notes, and snippets.

View Yaevh's full-sized avatar

Tomasz Malinowski Yaevh

  • 18:28 (UTC +02:00)
View GitHub Profile
@Yaevh
Yaevh / MaybeConverter.cs
Last active April 2, 2021 00:16
convert CSharpFunctionalExtensions.Maybe<T> to/from JSON using Newtonsoft.Json
public class MaybeConverter : JsonConverter
{
private static readonly Type _maybeGenericType = typeof(Maybe<>);
public override bool CanConvert(Type objectType)
{
return objectType.IsConstructedGenericType && objectType.GetGenericTypeDefinition() == _maybeGenericType;
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
@Yaevh
Yaevh / PagedListConverter.cs
Last active April 9, 2021 10:12
convert X.PagedList.IPagedList<T> to/from JSON using Newtonsoft.Json
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using X.PagedList;
namespace Yaevh
{
@Yaevh
Yaevh / SerializeModelStatePageFilter.cs
Last active April 23, 2025 11:00
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;
using NHibernate.Criterion;
using NHibernate.Impl;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
@Yaevh
Yaevh / NotifyingProperty.snippet
Created June 27, 2016 11:34
VS 2015 code snippet for notifying property
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propn</Title>
<Shortcut>propn</Shortcut>
<Description>Code snippet for notifying property</Description>
<Author>T.M.</Author>
</Header>
@Yaevh
Yaevh / ValidatedClassExample.cs
Created June 27, 2016 11:18
TM.ValidatorComponent usage exapmle
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace TM
{
public class ValidatedClassExample : INotifyDataErrorInfo
{
public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
@Yaevh
Yaevh / ValidatorComponent.cs
Last active June 27, 2016 11:17
Component for simple attribute-based validation (via INotifyDataErrrorsChanged) of INotifyPropertyChanged entities
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace TM
{
/// <summary>
/// Supports validation according to <see cref="INotifyDataErrorInfo"/> via validation attributes