Skip to content

Instantly share code, notes, and snippets.

View sliekens's full-sized avatar

Steven sliekens

View GitHub Profile
@sliekens
sliekens / DangerousOperation.cs
Last active August 29, 2015 13:56
LINQ-inspired try-catch wrapper.
/// <summary>
/// Factory. Provides a static method that initializes a new try-catch wrapper.
/// </summary>
public static class DangerousOperation
{
/// <summary>
/// Starts a new try-catch block.
/// </summary>
/// <param name="action">The 'try' block's action.</param>
/// <returns>Returns a new instance of the <see cref="TryCatchBlock"/> class that wraps the 'try' block.</returns>
@sliekens
sliekens / TypeMemberLayout.xaml
Last active October 12, 2024 07:34
StyleCop Type Member Layout for Resharper 9
<?xml version="1.0" encoding="utf-16"?>
<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns">
<TypePattern DisplayName="COM interfaces" Priority="2000">
<TypePattern.Match>
<And>
<Kind Is="Interface" />
<Or>
<HasAttribute Name="System.Runtime.InteropServices.InterfaceTypeAttribute" />
<HasAttribute Name="System.Runtime.InteropServices.ComImport" />
</Or>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
</Project>
# The build.rsp response file is a text file that contains MSBuild.exe command line switches.
# Each switch can be on a separate line or all switches can be on one line.
# Comment lines are prefaced with a # symbol.
# The @ switch is used to pass another response file.
# More information:
# https://msdn.microsoft.com/en-us/library/ms164311.aspx
# /nologo
#
@sliekens
sliekens / migrateToAutomaticPackageRestore.ps1
Created July 9, 2015 11:07
migrateToAutomaticPackageRestore
$files = gci -Recurse *.csproj
$files | %{
$file = $_
$xml = [Xml](Get-Content $file)
$nsm = [Xml.XmlNamespaceManager]$xml.NameTable
$nsm.AddNamespace('msb', $xml.DocumentElement.NamespaceURI)
$restorePackages = $xml.SelectSingleNode('//msb:RestorePackages', $nsm)
$restorePackages.ParentNode.RemoveChild($restorePackages)
$nugetTarget = $xml.SelectSingleNode('//msb:Target[@Name="EnsureNuGetPackageBuildImports"]', $nsm)
$nugetTarget.ParentNode.RemoveChild($nugetTarget)
@sliekens
sliekens / StringExtensions.cs
Last active August 29, 2015 14:27
StringExtensions
public static class StringExtensions
{
public static string Replace(this string instance, string oldValue, string newValue, StringComparison comparisonType)
{
if (instance == null)
{
throw new ArgumentNullException("instance");
}
if (string.IsNullOrEmpty(oldValue))
@sliekens
sliekens / cmdts.cs
Last active September 6, 2015 18:40
Add timestamps to console output
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
namespace Sys
{
class Program
{
namespace Common
{
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
[DebuggerDisplay(
"Display name = {Name}, alpha-2 = {TwoLetterCode}, alpha-3 = {ThreeLetterCode}, numeric = {NumericCode}")]
public sealed class Country
@sliekens
sliekens / App.csproj
Last active January 20, 2016 13:31
BuildPackage
<Target Name="AfterBuild" DependsOnTargets="BuildPackage" />
<Target Name="BuildPackage" DependsOnTargets="BuildPackageCore" Outputs="$(Packages)" Condition=" '$(BuildPackage)' == 'True' " />
<Target Name="BuildPackageCore">
<PropertyGroup>
<!-- Escape the OutDir's trailing slash -->
<_PackagesOutDir Condition="HasTrailingSlash('$(OutDir)')">"$(OutDir)\"</_PackagesOutDir>
<_PackagesOutDir Condition="!HasTrailingSlash('$(OutDir)')">"$(OutDir)\\"</_PackagesOutDir>
</PropertyGroup>
<Exec ContinueOnError="ErrorAndContinue" ConsoleToMSBuild="True" Command="&quot;$(SolutionDir)tools\nuget.exe&quot; pack &quot;$(MSBuildThisFileFullPath)&quot; -Symbols -IncludeReferencedProjects -OutputDirectory $(_PackagesOutDir) -Properties Configuration=$(Configuration)">
<Output TaskParameter="ConsoleOutput" ItemName="_out" />
@sliekens
sliekens / target.xml
Created January 25, 2016 08:28
A list of all <Target /> tags that ship with MSBuild / Visual Studio
C:\Program Files (x86)\MSBuild\12.0\Bin\Microsoft.Common.CurrentVersion.targets
<Target Name="_CheckForInvalidConfigurationAndPlatform"></Target>
<Target Name="Build" Condition=" '$(_InvalidConfigurationWarning)' != 'true' " DependsOnTargets="$(BuildDependsOn)" Returns="$(TargetPath)" />
<Target Name="BeforeBuild" />
<Target Name="AfterBuild" />
<Target Name="CoreBuild" DependsOnTargets="$(CoreBuildDependsOn)"></Target>
<Target Name="Rebuild" Condition=" '$(_InvalidConfigurationWarning)' != 'true' " DependsOnTargets="$(RebuildDependsOn)" Returns="$(TargetPath)" />
<Target Name="BeforeRebuild" />
<Target Name="AfterRebuild" />
<Target Name="BuildGenerateSources" DependsOnTargets="BuildGenerateSourcesTraverse;$(BuildGenerateSourcesAction)" />