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
/* | |
* Several times developers ask questions like: | |
* | |
* -What are IEnumerables, ICollections and ILists? Why should we use them? | |
* -What's the big deal about all those interfaces? I've always been using Concrete types and they get the job done! | |
* -Why are we using 'var's everywhere? | |
* | |
* Abstract programming allows developers to decouple their code from concrete implementations that could be regularly changed. Writing | |
* abstract code that adapts to modifications is a main characteristic of high quality code. Future proofing your code by using abstract | |
* types instead of concrete ones will allow API developers to roll out changes to their code without making their clients' lives a bit |
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
/* | |
* In C#, covariance and contravariance enable implicit reference conversion for array types, delegate types, and generic type arguments. | |
* Covariance preserves assignment compatibility and contravariance reverses it. | |
*/ | |
/************************************************************* Covariance *************************************************************/ | |
/* | |
* Covariance for enables implicit conversion of a more derived generic type to a less derived generic type. | |
* |
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
/* | |
* In this gist we will discuss OOP basics, this topic will cover: | |
* | |
* -Classes, properties, attributes, and methods. | |
* -Access modifiers. | |
* -Static vs Non-static methods. | |
* -Exceptions | |
* -Casting | |
*/ |
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
/// <summary> | |
/// A simple library to invoke private methods during runtime. Could be used while unit testing private functions. | |
/// </summary> | |
public class MethodInvoker | |
{ | |
private static MethodInfo GetMethod<T>(string methodName) => | |
typeof(T).GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance); | |
/// <summary> | |
/// Invokes a private void method. |
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 Program | |
{ | |
private static TestingContext Context { get; set; } | |
public static void Main(string[] args) | |
{ | |
/* | |
* A database transaction is a unit of work that represents a change in the database and is treated in a | |
* coherent and reliable way independent of other transactions. | |
* |
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 Program | |
{ | |
public static void Main(string[] args) | |
{ | |
DoSomethingAsync(); | |
Console.ReadLine(); | |
} | |
public static async void DoSomethingAsync() | |
{ |
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; | |
namespace Delegates.Tutorial | |
{ | |
public class DelegatesTutorial | |
{ | |
public delegate void TestDelegate(int x, bool y); | |
// A delegate declaration gets translated to a class of the same name by the compiler, this class inherits from the | |
// MulticastDelegate base class. The MulticastDelegate holds an InvocationList for each instance of the delegate, which is a | |
// list of all the methods called via the delegate in the same order as they are called |
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 Program | |
{ | |
private static object Locker { get; set; } | |
private static async void AwaitWithLock() | |
{ | |
/* | |
* Whenever you have code that might be contending over some resource, then you can place it in a lock statement | |
* to ensure thread safety. However, lock statements do not support async operations; you cannot await some task | |
* inside a locked code block. This was actually implemented to prevent deadlocks as the async operation might |
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
namespace Visitor | |
{ | |
class Program | |
{ | |
/* | |
* The Visitor pattern allows you to define new operations on a type without changing the type itself. | |
*/ | |
static void Main(string[] args) | |
{ | |
var employee = new Employee |
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
namespace Mediator | |
{ | |
class Program | |
{ | |
/* | |
* With the mediator pattern, communication between objects is encapsulated within a mediator object. Objects no longer communicate | |
* directly with each other, but instead communicate through the mediator. This reduces the dependencies between communicating objects, | |
* thereby reducing coupling. | |
*/ | |
static void Main(string[] args) |
OlderNewer