Skip to content

Instantly share code, notes, and snippets.

public class MessageBus
{
public void Send(IMessage message)
{
//Sends a single message.
}
public void SendAll(List<IMessage> messages)
{
foreach (var message in messages)
public void SendAll(IEnumerable<IMessage> messages)
{
foreach (var message in messages)
Send(message);
}
public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator()
}
public interface IMessage { }
public class RemoveOrderLineItem : IMessage { }
public class MessageBus
{
public void Send(IMessage message)
{
//Send the message.
}
//When you write:
public enum Role
{
System,
Manager,
Employee,
HumanResources
}
//...the compiler assumes you wrote:
Role manager = (Role)(1);
Role bogus = (Role)(-1);
Console.WriteLine(manager);
Console.WriteLine(bogus);
//Output:
// Manager
// -1
public class Role : Enumeration<Role>
{
public static readonly Role System = new Role(0, "System", "System", true);
public static readonly Role Manager = new Role(1, "Manager", "Michelle", false);
public static readonly Role Employee = new Role(2, "Employee", "Eric", false);
public static readonly Role HumanResources = new Role(3, "Human Resources", "Harry", false);
private Role(int value, string displayName, string personaName, bool testrole)
: base(value, displayName)
{
class Enumeration<TEnumeration>
where TEnumeration : Enumeration<TEnumeration>
public void ReceiveLambdaAsDelegate(Func<int, int> function) {...}
public void ReceiveLambdaAsExpression(Expression<Func<int, int>> expression) {...}
...
ReceiveLambdaAsDelegate(x => x*x);
ReceiveLambdaAsExpression(x => x*x);
public void ReceiveLambdaAsDelegate(Func<int, int> function) {...}
public void ReceiveLambdaAsExpression(Expression<Func<int, int>> expression) {...}
...
ReceiveLambdaAsDelegate(x => x*x);
ReceiveLambdaAsExpression(x => x*x);