Skip to content

Instantly share code, notes, and snippets.

View droyad's full-sized avatar

Robert Wagner droyad

View GitHub Profile
@droyad
droyad / gist:4711796
Created February 5, 2013 03:01
Testing Autofac registrations
var sb = new StringBuilder();
foreach (var src in container.ComponentRegistry.Sources.Select(s => s.ToString()).OrderBy(s => s))
sb.AppendLine(src);
sb.AppendLine();
foreach (var reg in container.ComponentRegistry.Registrations.OrderBy(r => r.Activator.LimitType.FullName))
{
sb.AppendLine(reg.Activator.LimitType.FullName);
sb.Append(" ").AppendLine(reg.Lifetime.GetType().Name);
protected override void Load(ContainerBuilder builder)
{
builder.Register(CreatedDbFunc).As<Func<Owned<IDb>>>().InstancePerDependency();
builder.Register(c => CreatedDbWithConnectionFunc()).As<Func<DbConnection, Owned<IDb>>>().InstancePerDependency();
builder.RegisterType<CurrentDatabase>().InstancePerMatchingLifetimeScope(LifetimeScopes.Workspace);
}
private Func<Owned<IDb>> CreatedDbFunc(IComponentContext context)
{
@droyad
droyad / gist:4527604
Created January 14, 2013 03:35
Support for NUnit's TestCase attribute
public class NUnitTestCaseStackTraceParser : AttributeStackTraceParser
{
protected override string GetAttributeType()
{
return typeof(TestCaseAttribute).FullName;
}
public override string ForTestingFramework
{
private struct Entry
{
public int hashCode;
public int next;
public TKey key;
public TValue value;
}
private Dictionary<TKey, TValue>.Entry[] entries;
private int[] buckets;
// Not written in an IDE
class MyViewModel
{
MyViewModelStepEnum CurrentStep { get; set; }
enum MyViewModelStepEnum {
Step 1, Step2
}
}
4000000000000000000000001d-4000000000000000000000000d
4000000000000000000000001m-4000000000000000000000000m
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<!-- These can go into the global styles-->
<Style TargetType="{x:Type Label}">
<Setter Property="TextBlock.TextAlignment" Value="Right" />
<Setter Property="Margin" Value="5,5,10,5" />
<Setter Property="Height" Value="30" />
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<!-- These can go into the global styles-->
<Style TargetType="{x:Type Label}">
<Setter Property="TextBlock.TextAlignment" Value="Right" />
<Setter Property="Margin" Value="5,5,10,5" />
</Style>
using (Stream stream = new FileStream("file.txt", FileMode.OpenOrCreate))
{
using (StreamWriter writer = new StreamWriter(stream))
{
// Use the writer object...
}
}
Stream stream = null;
try
{
stream = new FileStream("file.txt", FileMode.OpenOrCreate);
using (StreamWriter writer = new StreamWriter(stream))
{
stream = null;
// Use the writer object...
}
}