• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Reflection

TypeScript – Enumerating object properties with Object.keys

June 21, 2019 by Robert Leave a Comment

One of the benefits of JavaScript (and therefore TypeScript) is being able to do whatever you want with objects.  This can be dangerous, of course, because of type promiscuity – which is one thing that TypeScript addresses. via GIPHY Object.keys Sometimes it is still useful to just loop through each property on an object in … [Read more…]

Posted in: JavaScript, Reflection, Typescript, Web Development Tagged: Gotcha, JavaScript, Reflection, Typescript

Autofac–Automatically registering generics via constructors

May 17, 2019 by Robert Leave a Comment

Recently I had a situation where I had a class and interface to make a generic service which would do something based on whatever type is provided.  (Obviously, it was not so contrived…) These would then get injected to other classes to be used as necessary: Which works fine… as long as you remember to … [Read more…]

Posted in: .NET Core, C#, Reflection Tagged: .NET, AutoFac, C#, Csharp, DependencyInjection, Generics, IoC, Reflection

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

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# Unit Testing object equality without implementing .Equals

August 24, 2018 by Robert Leave a Comment

Recently I was trying to write a unit test testing to see if one object was equal to another.  The objects themselves were simple, just a collection of built-in types, so it should be easy to test. .Equals However, since I didn’t implement .Equals, C# doesn’t natively know how to check if the objects are … [Read more…]

Posted in: C#, Reflection, Unit Testing Tagged: C#, Csharp, Equals, PixieDust, Reflection, Testing, UnitTesting

C# Reflection with Generics

June 22, 2018 by Robert 1 Comment

If you find yourself writing a lot of the same code (or copy/pasting it) for similar constructs, you should probably consider using generics.  It allows you to write a base class full of functionality that is basically the same across all of different classes, but in a way that doesn’t tie you to a specific … [Read more…]

Posted in: .NET Core, C#, Generic, Reflection Tagged: .NET, C#, Constructor, Generics, Parameter, Reflection, Template, Type

Automatically registering properties as implementations in AutoFac

May 25, 2018 by Robert Leave a Comment

In this post I talked about building out a configuration service that could be split into various areas of concerns so that each piece can be injected where it makes sense (without all of the noise of the rest of the configuration). Previously, the registration looked like this: Reflection With reflection, we can loop through … [Read more…]

Posted in: .NET Core, C#, IoC, Reflection Tagged: AutoFac, C#, Configuration, DI, IoC, Reflection

Enumerating constants from a class

December 15, 2017 by Robert Leave a Comment

Reflection is kind of like black magic, and whenever I use it I feel like some kind of wizard.  The ability to look into objects and even invoke private methods is pretty darn powerful.  It’s not all that magical, of course, since it is built into the framework… however, you should still be careful because … [Read more…]

Posted in: C#, Reflection Tagged: C#, consts, enumeration, Reflection

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