This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write avro file to a memory stream, then read it out again, using reflection. | |
// Based on the very sparse C# docs from https://avro.apache.org/docs/1.11.1/api/csharp/html/md_src_apache_main_Reflect_README.html | |
// combined with the Java docs from https://avro.apache.org/docs/1.11.1/getting-started-java/ | |
var baseClassSchema = @" | |
[ | |
{ ""type"" : ""record"", ""name"" : ""Derived1"", ""fields"" : | |
[ | |
{ ""name"" : ""A"", ""type"" : ""string""}, | |
{ ""name"" : ""B"", ""type"" : ""int""} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExpressionReplacer : ExpressionVisitor | |
{ | |
private readonly Func<Expression, Expression> replacer; | |
public ExpressionReplacer(Func<Expression, Expression> replacer) | |
{ | |
this.replacer = replacer; | |
} | |
public override Expression Visit(Expression node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using static System.Console; | |
using static System.Threading.Thread; | |
using Throwable = System.Exception; | |
public class Parent | |
{ | |
public string Name => "Parent"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using JetBrains.Annotations; | |
namespace Truenorth.Utility.Contract | |
{ | |
/// <summary> | |
/// Some utility methods to help us create assertions within our methods. | |
/// We would have liked to use Microsoft's CodeContracts, but they made them | |
/// too clunky. | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is a benchmarking template I use in LINQPad when I want to do a | |
* quick performance test. Just give it a couple of actions to test and | |
* it will give you a pretty good idea of how long they take compared | |
* to one another. It's not perfect: You can expect a 3% error margin | |
* under ideal circumstances. But if you're not going to improve | |
* performance by more than 3%, you probably don't care anyway.*/ | |
void Main() | |
{ | |
// Enter setup code here | |
var actions = new[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var actions = new[] | |
{ | |
new TimedAction("first", () => | |
{ | |
// Insert logic here. | |
}), | |
new TimedAction("second", () => | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void AllRepositoriesShouldBeCreatableViaDependencyInjection() | |
{ | |
// By doing this in parallel, we simultaneously test whether our | |
// DI stuff can handle lots of multi-threaded requests. | |
var repositoryTypes = from a in CoreAssemblies.AsParallel() | |
from t in a.GetTypes() | |
where t.Name.EndsWith("Repository") | |
// Don't bother if they've been flagged as factory-built | |
where !t.GetCustomAttributes(typeof (FactoryBuiltAttribute), false).Any() |