Skip to content

Instantly share code, notes, and snippets.

public interface ILoadable { }
public class Person : ILoadable { }
public interface ILoader<T>
where T : ILoadable
{
void Load(T loadable);
}
public void Test()
{
ILoadable order = new Order();
ILoader loader = new PersonLoader();
loader.Load(order); //What happens here?
}
//Where Order is an ILoadable
public class BaseType {
}
public class MyType : BaseType {
}
public void Test(MyType obj) {
if (obj is BaseType) {
Console.WriteLine("Base");
} else {
public class AsyncSerializerWrapper
{
public AsyncSerializerWrapper(NetworkStream stream)
{
_stream = stream;
}
private NetworkStream _stream;
public IAsyncResult BeginWriteObject(object obj, AsyncCallback callback)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
@akmad
akmad / gist:959168
Created May 6, 2011 15:32
Simple Update
UPDATE MyTable SET SomeColumn = 'Test' WHERE RecordDate > '01-01-2001'
SELECT @@ROWCOUNT AS UpdatedRecords
@akmad
akmad / gist:1058699
Created July 1, 2011 14:50
LinqToSql Mocking
/// <summary>
/// Represents a repository context.
/// </summary>
/// <remarks>
/// Based on: http://www.iridescence.no/post/Linq-to-Sql-Programming-Against-an-Interface-and-the-Repository-Pattern.aspx
/// </remarks>
public interface IDataContext : IDisposable
{
/// <summary>
/// Gets or sets the connection string.
var d = new Dictionary<string, MyStruct>();
var s = new MyStruct();
s.Value = 10;
d["test"] = s;
var s2 = d["test"];
s2.Value = 11;
//What get's written here?
SELECT * FROM
(SELECT TOP 25 ID, ...
FROM MyTable
ORDER BY ID DESC) AS Z
ORDER BY Z.ID ASC
@akmad
akmad / gist:1320523
Created October 27, 2011 19:11
ExecuteAndReport
public void ExecuteAndReport(Action a)
{
a();
worker.ReportProgress((int)((float)reader.BaseStream.Position / (float)reader.BaseStream.Length) * 100);
}