Skip to content

Instantly share code, notes, and snippets.

Patrick Lioi plioi

  • Austin, TX
Block or report user

Report or block plioi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View TypeMismatch.cs
public class MessageBus
{
public void Send(IMessage message)
{
//Sends a single message.
}
public void SendAll(List<IMessage> messages)
{
foreach (var message in messages)
View UsingIEnumerable.cs
public void SendAll(IEnumerable<IMessage> messages)
{
foreach (var message in messages)
Send(message);
}
View IEnumerable.cs
public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator()
}
View TypeMismatch.cs
public interface IMessage { }
public class RemoveOrderLineItem : IMessage { }
public class MessageBus
{
public void Send(IMessage message)
{
//Send the message.
}
View enum.cs
//When you write:
public enum Role
{
System,
Manager,
Employee,
HumanResources
}
//...the compiler assumes you wrote:
View unsafe.cs
Role manager = (Role)(1);
Role bogus = (Role)(-1);
Console.WriteLine(manager);
Console.WriteLine(bogus);
//Output:
// Manager
// -1
View Role.cs
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)
{
View GenericTypeConstraint.cs
class Enumeration<TEnumeration>
where TEnumeration : Enumeration<TEnumeration>
View Lambdas.cs
public void ReceiveLambdaAsDelegate(Func<int, int> function) {...}
public void ReceiveLambdaAsExpression(Expression<Func<int, int>> expression) {...}
...
ReceiveLambdaAsDelegate(x => x*x);
ReceiveLambdaAsExpression(x => x*x);
View Lambdas.cs
public void ReceiveLambdaAsDelegate(Func<int, int> function) {...}
public void ReceiveLambdaAsExpression(Expression<Func<int, int>> expression) {...}
...
ReceiveLambdaAsDelegate(x => x*x);
ReceiveLambdaAsExpression(x => x*x);
You can’t perform that action at this time.