• About
  • Privacy Policy
  • Utilities
Darchuk.NET

C#

C# Inline If Gotcha

April 26, 2019 by Robert Leave a Comment

So I was writing an inline if statement the other day… you know the ones – booleanStatement ? resultIfTrue : resultIfFalse; It was pretty simple, so I didn’t think too much about it until I ran some unit tests…. via GIPHY Here’s what my code kind of looked like: So, what would you expect the … [Read more…]

Posted in: C#, Debugging Tagged: C#, Debugging, Inline If, Weird

ASP.NET Core 2–Enabling SignalR logging

April 19, 2019 by Robert 1 Comment

Sometimes you just need some logging to do a sanity check that things are actually working the way that you’re expecting. via GIPHY Here’s how to turn logging on in ASP.NET Core 2 for SignalR: I’ve had to look this up more than twice, and its not exactly easy to find in the Microsoft docs, … [Read more…]

Posted in: .NET Core, ASP.NET, C#, Debugging, SignalR Tagged: .NET Core, ASP.NET, C#, Logging, SignalR

Serializing XUnit test cases

April 12, 2019 by Robert Leave a Comment

XUnit has some cool stuff like Theory, which lets you write multiple test cases to run against the same test code.  This lets you test multiple paths with different inputs without having to write multiple tests.  This can save you a lot of time as you can cover a lot of ground with a single … [Read more…]

Posted in: .NET Core, C#, Unit Testing Tagged: C#, Csharp, IXunitSerializable, unit testing, XUnit

C# overwriting a static field with reflection

April 5, 2019 by Robert Leave a Comment

Imagine that you have a NuGet package containing a bunch of static strings.  These fields are intended to be used instead of magic strings, making it so anything that takes a dependency on this NuGet package will all be on the same page about these unique keys. Now suppose that these keys also represent the … [Read more…]

Posted in: .NET Core, C#, Reflection, Unit Testing Tagged: Csharp, Reflection, Static, Testing

ASP.NET Core – Unit Testing a file upload

March 29, 2019 by Robert 1 Comment

Last week I wrote about how to upload a file from a website using Angular and .NET Core.  Writing tests for this is mostly straightforward, but there’s a few gotchas that I thought I would write down for the next time I need to do this.  The front end tests are pretty trivial – you … [Read more…]

Posted in: .NET Core, C#, Unit Testing, Web API, Web Development Tagged: .NET Core, ASP.NET, ASP.NET Core, File Upload, IFormCollection, IFormFile, Testing, unit testing

Uploading a file from a website

March 22, 2019 by Robert 1 Comment

Uploading a file from a website is pretty simple, but I always have to look it up.  There’s all sorts of different technologies and frameworks that work with the web, so I just thought I would write down how I got it to work so that next time I can just come back here and … [Read more…]

Posted in: .NET Core, Angular, ASP.NET, C#, JavaScript, Typescript, Web API, Web Development Tagged: .NET Core, Angular, ASP.NET, File, MemoryStream, Typescript, Upload, Web API

Colorful Console App

February 15, 2019 by Robert Leave a Comment

In a C# console application, you can change the color of the text emitted by Console.WriteLine by setting Console.ForegroundColor and Console.BackgroundColor.  It’s pretty straightforward, but if you want to make the output have different colors to denote different things, its kind of cumbersome to have to set the color and then write the output, and … [Read more…]

Posted in: C#, Generic Tagged: C#, Colors, Console, Csharp, Terminal

Waiting for a keypress asynchronously in a C# console app

February 8, 2019 by Robert 2 Comments

This one’s kind of specific, but sometimes when you’re writing a console app that does a lot of asynchronous stuff, and you want to cancel it at any time by pressing escape.  via GIPHY However, Console.ReadKey is blocking… so that’s not super great. CancellationToken First, make use of the cancellation tokens.  I’ve talked about them … [Read more…]

Posted in: .NET Core, Asynchronous, C#, Concurrency Tagged: async, C#

Getting Nested Classes With Reflection

February 1, 2019 by Robert Leave a Comment

Are you tired of feeling like your code is meaningless?  Sick of people not referring to your code as “black magic,” or struggling to gain recognition from your boss for writing sufficiently obfuscated code?If you’ve answered “yes” to any of the above, Reflection might be for you! via GIPHY Reflection I’ve talked about reflection a … [Read more…]

Posted in: C#, Reflection, Uncategorized, Unit Testing Tagged: C#, Reflection, Testing

C#–Writing Enum extension methods

January 25, 2019 by Robert 1 Comment

Sometimes I find myself wanting a quick way to compare an enum with a list of other enums…  Basically, if the enum is one of these, then do this.  It’s pretty easy to do with Linq, but if you want to do it a few times in a few other places, it pays to be … [Read more…]

Posted in: C#, Generic Tagged: C#, enum, equality, extension
« Previous 1 2 3 4 … 7 Next »

Recent Posts

  • Allowing trailing JSON commas in ASP.NET Core 3
  • YADNC3JSG–Yet Another .NET Core 3.0 JSON Serializer Gotcha
  • Logging in a .NET Core 3 SignalR client
  • .NET Core 3 unit testing project sdk
  • .NET Core 3.0 Upgrade–New JSON Serializer Gotchas

Recent Comments

  1. Robert on C# Setting Socket Keep-Alive
  2. Oliver Schramm on C# Setting Socket Keep-Alive
  3. John Anderson on Waiting for a keypress asynchronously in a C# console app
  4. Ronald Garlit on .NET Core 3 unit testing project sdk
  5. Ronald Garlit on .NET Core 3 unit testing project sdk

Copyright © 2025 Darchuk.NET.

Omega WordPress Theme by ThemeHall