Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
AlexArchive / Delegate.cs
Last active August 29, 2015 14:06
Generating expressions at runtime
var containers = new[]
{
new Container { Value = "bag" },
new Container { Value = "bed" },
new Container { Value = "car" }
};
var filteredResults =
containers.Where(container => container.Value.Contains("a"))
@AlexArchive
AlexArchive / Program.cs
Created September 8, 2014 15:04
(F# versus. C#) Primitive form of ROT13
using System;
using System.Linq;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(EncryptText("THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG"));
@AlexArchive
AlexArchive / Program.cs
Created September 8, 2014 13:49
(F# versus. C#) Print all file paths in both top level directories and sub directories.
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ConsoleApplication9
{
class Program
{
static void Main()
{
@AlexArchive
AlexArchive / 0ReadMe.md
Created September 3, 2014 15:23
Impress your friends with your terse and expressive reflection code.

Before:

public static class Calculator
{
    public static int Add(
        int numberOne, 
        int numberTwo, 
        int numberThree, 
        int numberFour, 

int numberFive)

@AlexArchive
AlexArchive / ExtensionMethod.cs
Created September 3, 2014 13:49
Every day expressions
public static class ExtensionMethod
{
public static void SetValue<T>(
this T target,
Expression<Func<T, object>> expression, object value) where T : Control
{
var memberExpression = expression.Body as MemberExpression;
if (memberExpression != null)
{
var property = memberExpression.Member as PropertyInfo;
open System
let highLowGame () =
let rng = new Random()
let secretNumber = rng.Next() % 100
let rec highLowGameStep () =
printfn "Guess the secret number:"
let guessStr = Console.ReadLine()
case "1":
Console.WriteLine("Select which of the following to add to cart by entering it's number:");
foreach (var product in result)
{
Console.WriteLine(" {0}. {1}, Stock: {2}, Price: {3}", product.RecordNumber, product.Name, product.Stock, product.Price);
}
int ProductInput = Convert.ToInt32(Console.ReadLine());
// answer..
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
var converter = new HotkeyConverter();
var keys = (value == null) ? Keys.None : (Keys) converter.ConvertTo(value, typeof(Keys));
value = base.EditValue(context, provider, keys);
return converter.ConvertFrom(value);
}
internal class HotkeyConverter : KeysConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destination
{
if (destinationType == typeof(Keys))
{
Hotkey hotkey = (Hotkey) value;
if (hotkey != null)
{
Should I unit test the repository and the controller? I probably only need to verify that the already-tested
repository has been called into.
Should I test All_ReturnsAll and All_OrdersByPublish date or just the former?