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 MessageBus | |
{ | |
public void Send(IMessage message) | |
{ | |
//Sends a single message. | |
} | |
public void SendAll(List<IMessage> messages) | |
{ | |
foreach (var message in messages) |
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 void SendAll(IEnumerable<IMessage> messages) | |
{ | |
foreach (var message in messages) | |
Send(message); | |
} |
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 interface IEnumerable<out T> : IEnumerable | |
{ | |
IEnumerator<T> GetEnumerator() | |
} |
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 interface IMessage { } | |
public class RemoveOrderLineItem : IMessage { } | |
public class MessageBus | |
{ | |
public void Send(IMessage message) | |
{ | |
//Send the message. | |
} |
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
//When you write: | |
public enum Role | |
{ | |
System, | |
Manager, | |
Employee, | |
HumanResources | |
} | |
//...the compiler assumes you wrote: |
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
Role manager = (Role)(1); | |
Role bogus = (Role)(-1); | |
Console.WriteLine(manager); | |
Console.WriteLine(bogus); | |
//Output: | |
// Manager | |
// -1 |
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 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) | |
{ |
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
class Enumeration<TEnumeration> | |
where TEnumeration : Enumeration<TEnumeration> |
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 void ReceiveLambdaAsDelegate(Func<int, int> function) {...} | |
public void ReceiveLambdaAsExpression(Expression<Func<int, int>> expression) {...} | |
... | |
ReceiveLambdaAsDelegate(x => x*x); | |
ReceiveLambdaAsExpression(x => x*x); |
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 void ReceiveLambdaAsDelegate(Func<int, int> function) {...} | |
public void ReceiveLambdaAsExpression(Expression<Func<int, int>> expression) {...} | |
... | |
ReceiveLambdaAsDelegate(x => x*x); | |
ReceiveLambdaAsExpression(x => x*x); |
OlderNewer