This file contains hidden or 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
| [ApiController] | |
| [Route("[controller]")] | |
| public class PersonController : ControllerBase | |
| { | |
| [HttpGet] | |
| public IActionResult Get() | |
| { | |
| var person = new Person | |
| { | |
| FirstName = "Sam", |
This file contains hidden or 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 Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var memberExpression = GetMemberFromExpression(() => Test); | |
| Console.WriteLine(memberExpression.Member.Name); | |
| Console.ReadLine(); | |
| } | |
| private static int Test => 10; |
This file contains hidden or 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 Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| //If this is var, the result will be 0 | |
| IHasNumber hasNumber = new StructWithNumber { Number = 0 }; | |
| IncrementNumber(hasNumber); | |
| Console.WriteLine(hasNumber.Number); | |
| } |
This file contains hidden or 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 Microsoft.VisualStudio.TestTools.UnitTesting; | |
| using System; | |
| using System.Reactive.Subjects; | |
| using System.Threading.Tasks; | |
| namespace DecoupledMessaging | |
| { | |
| [TestClass] | |
| public class UnitTest1 | |
| { |
This file contains hidden or 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 Microsoft.Extensions.Logging; | |
| using Microsoft.Extensions.Logging.Abstractions; | |
| using System; | |
| namespace ConsoleApp | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| new Example().Print("Hello World!"); |
This file contains hidden or 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 ConsoleApp | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| new Example().Print("Hello World!"); | |
| } | |
| } | |
| public class Example |
This file contains hidden or 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 Example(ILoggerFactory? loggerFactory = null) | |
| { | |
| _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance; | |
| _logger = _loggerFactory.CreateLogger<Example>(); | |
| } |
This file contains hidden or 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 abstract class BaseClass | |
| { | |
| protected ILogger Logger { get; } | |
| protected BaseClass(ILogger logger) | |
| { | |
| Logger = logger; | |
| } | |
| } | |
| public class ConcreteClass : BaseClass | |
| { |
This file contains hidden or 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 Print(string message) | |
| { | |
| using (var logScope = _logger.BeginScope("Begin scope")) | |
| { | |
| _logger.LogTrace("Logged message: {message}", message); | |
| Console.WriteLine(message); | |
| } | |
| } | |
| public void Print(string message) |
This file contains hidden or 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 IList<string> GetFilteredStrings() | |
| { | |
| Func<string, bool> predicate = a => a.Length == 1; | |
| return new List<string> { "321", "21", "1" }.Where(predicate).ToList(); | |
| } |
OlderNewer