Skip to content

Instantly share code, notes, and snippets.

@robfe
robfe / DynamicBDDBase.cs
Created May 19, 2010 14:48
Dynamic dispatch + printing of BDD steps
// Complementary to http://gist.github.com/406014. Just swap your BDD<T> base class for DBDD
// Also licensed under MSPL/FreeBSD/ISC
public abstract class DBDD
{
public readonly dynamic Given;
public readonly dynamic When;
public readonly dynamic Then;
public readonly dynamic And;
@robfe
robfe / Regionator.cs
Created June 26, 2010 15:07
Extract #regions into individual txt files for INCLUDETEXT in word...
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Regionator
{
public class Program
{
const int TargetSpacesPerIndent = 3;
@robfe
robfe / CodeTimer.cs
Created July 1, 2010 15:18
using(new CodeTimer("connecting")){connect();}
public class CodeTimer : IDisposable
{
private readonly string _message;
private readonly Stopwatch _sw = new Stopwatch();
public CodeTimer(string message)
{
_message = message;
_sw.Start();
}
@robfe
robfe / Extensions.cs
Created October 11, 2010 08:45
ObservePropertyChanged extension method (INotifyPropertyChanged.Property => IObservable)
public static class Extensions
{
public static IObservable<TProperty> ObservePropertyChanged<TNotifier, TProperty>(
this TNotifier notifier,
Expression<Func<TNotifier, TProperty>> propertyAccessor,
bool startWithCurrent = false)
where TNotifier : INotifyPropertyChanged
{
// Parse the expression to find the correct property name.
@robfe
robfe / FillingLine.cs
Created October 11, 2010 12:07
Path subclass for drawing a line that fills its available space in silverlight
public class FillingLine : Path
{
Size lastFinalSize;
protected override Size MeasureOverride(Size availableSize)
{
return new Size(0, 0);
}
protected override Size ArrangeOverride(Size finalSize)
@robfe
robfe / AutoInterfacer.tt
Created October 26, 2010 21:46
Reflects over a class and generates an interface, and an interface wrapper for your class
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension="Generated.cs" #>
<#@ assembly name="System.Core" #>
<#/* Modify the following assembly reference(s) to include the classes you are interested in: */#>
<#@ assembly name="c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone\System.Xml.dll" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Runtime.Remoting.Messaging" #>
@robfe
robfe / CsProjReferencesToDot.cs
Created October 27, 2010 14:39
Analyses all the csproj files in a directory and generates a dot (www.graphviz.com) graph of the project references, including silverlight application references
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ReferenceReader
{
@robfe
robfe / ObservableExtensions.tt
Created November 29, 2010 10:17
T4 template to generate some useful N-Tuple overloads of common System.Reactive extension methods
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension="Generated.cs" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Runtime.Remoting.Messaging" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
using System;
using System.Linq;
using System.Reactive;
@robfe
robfe / VirtualContentPresenter.cs
Created February 3, 2011 09:50
Helps you to keep the number of visuals in your visual tree down
/// <summary>
/// Easy way to switch between no content template and some content template in silverlight
/// Helps you to keep the number of visuals in your visual tree down.
/// </summary>
public class VirtualContentPresenter : ContentPresenter
{
public static readonly DependencyProperty VirtualContentTemplateProperty = DependencyProperty.Register("VirtualContentTemplate",
typeof(DataTemplate),
typeof(VirtualContentPresenter),
new PropertyMetadata(null, (o, args) => ((VirtualContentPresenter) o).VirtualContentPropertyChanged()));
@robfe
robfe / Resources.tt
Created February 27, 2011 16:49
Strongly typed access to Content files for XNA
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ import namespace="System.IO"#>
<#@ import namespace="System.Linq"#>
<#@ import namespace="System.Collections.Generic"#>
<#@ import namespace="System.Runtime.Remoting.Messaging" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
<#@ assembly name="System.Core.dll"#>
<#@ output extension=".Generated.cs" #>
<#