Skip to content

Instantly share code, notes, and snippets.

View daiplusplus's full-sized avatar
💀

Dai daiplusplus

💀
View GitHub Profile
@daiplusplus
daiplusplus / UpdateVSTemplates.ps1
Created June 29, 2018 00:10
PowerShell script to add using System.Globalization; and using System.Text to every C# file in every ItemTemplate and ProjectTemplate
View UpdateVSTemplates.ps1
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
###########################################
## Summary
# This script changes the namespace imports in your C# ItemTemplates and ProjectTemplates and improves your default AssemblyInfo.cs files.
# It is designed for Visual Studio 2017, but should work with all Visual Studio versions going back as far as Visual Studio 2002, just set $vsCommon7IDE correctly.
###########################################
@daiplusplus
daiplusplus / Program.cs
Last active July 11, 2018 02:21
RedGate .NET Reflector - Toolbar and panel border fix
View Program.cs
// I use Redgate .NET Reflector ( https://www.red-gate.com/products/dotnet-development/reflector/index ) regularly and there's just a couple of things about it that irritate me:
// 1. The toolbars at the top are on two lines which wastes space. This program automatically moves the toolbar next to the menubar to save space.
// 2. The left-hand-side tree-view has a 1px black border set for some reason, this looks ugly. This program removes the border.
// Instructions:
// 1. Save this file somewhere.
// 2. Create a new C# Class-library (DLL) project in Visual Studio. Use AnyCPU.
// 3. Add a reference to Reflector.exe
// 4. Build.
// 5. Open reflector and add the output assembly to its add-ins list.
@daiplusplus
daiplusplus / LazyOrm.tt
Created September 18, 2018 01:51
LazyOrm T4 - Generate trivial INSERTs for each table and query result types for SELECT *.sql files
View LazyOrm.tt
<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
@daiplusplus
daiplusplus / EnumTraits.cs
Last active November 11, 2019 07:22
EnumTraits<T> - Common operations on enums with C#'s `Enum` type constraint. Uses emited IL for fast enum operations without boxing.
View EnumTraits.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
namespace Jehoel
{
/// <summary>Derived from https://devblogs.microsoft.com/premier-developer/dissecting-new-generics-constraints-in-c-7-3/</summary>
public static class EnumTraits<TEnum>
where TEnum : struct, Enum
View answer.md

As an opening remark, remember it's 2019 and WCF is obsolete and I"m personally glad to see it gone, and I strongly recommend against using WCF for any new projects and I advise people to transition away from WCF as soon as possible.

Does WCF use sockets internally for the communication in all cases. In other words is WCF a wrapper around sockets and is built upon them?

Short-answer: Yes, with an "if".
Long-answer: No, with a "but".

WCF is a .NET platform originally designed for SOAP - and SOAP has many different transports (most notably HTTP), but also supports other protocols (that all follow SOAP's general design, unfortunately), such as net.tcp which is essentially a binary form of SOAP.

On Win32, networking is accomplished using Winsock - which is Microsoft's implementation of the BSD Sockets API - so if you're using WCF to communicate between machines then eventually your messages will pass-through Winsock - but this doesn't necessarily have to be the case - for example, you can avoid Wins

@daiplusplus
daiplusplus / ReimplementInterface.cs
Created May 26, 2020 06:15
Subclasses can reimplement interfaces to effectively override non-virtual methods
View ReimplementInterface.cs
void Main()
{
BaseClass b = new BaseClass();
DerivedClass d = new DerivedClass();
ReimplementedDerivedClass r = new ReimplementedDerivedClass();
//
b.GetX().Dump( b.GetType().Name ); // "1"
@daiplusplus
daiplusplus / DataUris.css.tt
Created August 21, 2020 08:10
Automatically generate CSS file with data: URIs in custom properties
View DataUris.css.tt
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".css" #>
<#
View Sum_performance.cs
// This file compares a variety of techniques to get a SUM of a list of integers.
// For https://stackoverflow.com/questions/66643270/why-does-list-sum-perform-poorly-as-compared-to-a-foreach#comment117808641_66643270
// I get these results with this environment:
// CPU: i7-770HQ (Dell XPS laptop)
// OS: Windows 10 x64
// .NET Core 5
// Release build, AnyCPU
/*
@daiplusplus
daiplusplus / ViewModels.definitions.cs
Created April 18, 2021 02:44
ViewModels.tt - My T4 script to generate the tedious bits of WPF+MVVM+DI ViewModel types.
View ViewModels.definitions.cs
//<#+
#if !T4 // `T4` is defined in ViewModels.tt, see line 1: `compilerOptions="/d:T4"`, ahh!
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@daiplusplus
daiplusplus / ProxyStream.cs
Created March 20, 2020 11:10
ProxyStream for .NET Framework, .NET Standard and .NET Core
View ProxyStream.cs
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace WhyAreYouCopyingCodeFromGitHub
{
/// <summary>
/// <para>This class directly subclasses <see cref="System.IO.Stream"/> and overrides every virtual member. All members directly invoke their corresponding method on the wrapped <see cref="System.IO.Stream"/> object. Only the members <see cref="Stream.CreateWaitHandle"/>, <c>Stream.CreateObjRef</c> (not present in .NET Standard) and <see cref="Stream.ObjectInvariant"/> are not overridden.</para>
/// <para>This class is intended to be used as the base class for a subclass that only wants to override individual methods when proxying a <see cref="Stream"/> instead of implementing all of Stream's abstract methods. This class can also be instantiated directly and used as a preventative measure against consumers of your <see cref="System.IO.Stream"/> objects from being disposed by using the <see cref="LeaveOpen"/> constructor parameter.</para>