Skip to content

Instantly share code, notes, and snippets.

View sandord's full-sized avatar

Sandor Drieënhuizen sandord

View GitHub Profile
@sandord
sandord / ef6.md
Last active June 12, 2018 20:56
Entity Framework 6 Tips & Tricks
@sandord
sandord / ReflectionHelper.cs
Created February 7, 2014 12:09
Reflection helper
namespace ...
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
/// <summary>
/// Provides static methods that aid in performing reflection related operations.
@sandord
sandord / gist:d9c04a40085425329a09
Last active December 29, 2015 17:29
Replace multi line property get/set by single line variant in Visual Studio
Open the find/replace (in files) dialog.
Enable regular expressions.
Replace
([\n]*)([\s]*)([\n]*){([\s])([\n])([\s]*)get;([\n]*)([\s]*)set;([\s])([\n])([\s]*)}
by
{ get; set; }
@sandord
sandord / gist:443725
Last active October 18, 2018 11:45
Custom exception pattern
[Serializable]
public class CustomException : Exception
{
public CustomException() { }
public CustomException(string message) : base(message) { }
public CustomException(string message, System.Exception innerException) : base(message, innerException) { }
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
//...
@sandord
sandord / gist:400557
Last active December 1, 2022 14:49
Disposable pattern
public class MyClass : IDisposable
{
/// <summary>
/// Finalizes an instance of the <see cref="MyClass"/> class. Releases unmanaged
/// resources and performs other cleanup operations before the current instance is
/// reclaimed by garbage collection.
/// </summary>
~MyClass()
{
this.Dispose(false);
@sandord
sandord / gist:400553
Last active September 24, 2023 08:17
Get property name from lambda expression
using System.Linq.Expressions;
/// <summary>
/// Returns the name of the specified property of the specified type.
/// </summary>
/// <typeparam name="T">The type the property is a member of.</typeparam>
/// <param name="property">The property expression.</param>
/// <returns>The property name.</returns>
public static string GetPropertyName<T>(Expression<Func<T, object>> property)
{