Skip to content

Instantly share code, notes, and snippets.

@eliottrobson
eliottrobson / BooleanExpressionReducer.cs
Last active November 12, 2021 16:44
Boolean Expression Reducer
/// <summary>
/// Reduces boolean expressions to improve performance with generated queries.
/// <example>
/// For example:
/// <code>
/// Expression<Func<User, FollowingData>> projection = u => new FollowingData
/// {
/// UserId = u.Id,
/// FollowersCount = u.Followers.Count,
/// IsFollowing = currentUserId.HasValue && u.Following.Any(f => f.UserId == currentUserId.Value)
@litetex
litetex / Description.md
Last active March 2, 2024 03:12
Serilog (C#): How to get current MethodName, FileName/Path and LineNumber without reflection

Serilog (C#): How to get the current MethodName, FileName/Path and LineNumber without reflection

This is a simple setup for reflectionless logging with serilog using caller information (and a single static class).

See also https://stackoverflow.com/a/46905798

Log.cs

Create your own Log.cs in your Root-Namespace (you can use the class below).

This class is required to detect where the call is coming from; it uses Caller-Information to speed up the program execution, because the attributes are resolved at compile-time.

@romeshniriella
romeshniriella / Log4NetTraceListener.cs
Created August 11, 2017 07:15
A Log4Net based trace listener for system.diagnostics.tracing
using DinkLabs.Runtime.Logging;
namespace DinkLabs.Web.Core.Logging
{
public class Log4NetTraceListener : System.Diagnostics.TraceListener
{
private readonly ILog _log;
public Log4NetTraceListener(string provider)
{
@carols10cents
carols10cents / c#-to-rust.md
Last active April 18, 2024 22:55
C# to Rust Cheat Sheet

Thanks to @seejee for making this for me!!!

C# to Rust Cheat Sheet

The goal of this is to have an easily-scannable reference for the most common syntax idioms in C# and Rust so that programmers most comfortable with C# can quickly get through the syntax differences and feel like they could read and write basic Rust programs.

What do you think? Does this meet its goal? If not, why not?

Variables