Extending the C# Registry-based configuration class

Extending the C# Registry-based configuration class
Photo by Kevin Jarrett on Unsplash

So we now have our RegistryConfig class ready... but how can we make it better?!

Use reflection!

We will use reflection to perform initialization on the classes properties, so that the settings can be added to the registry straight away. This will ensure that the registry has all the properties you have set up in your class have been initialized in the registry with the default values.

Getting the classes properties

The method below will get a list of all the properties in your class!

We mark this as virtual so we can filter out properties we don’t want to initialize into the registry.

Here is the initialization method

This will invoke the getter in each of the properties that will add the value to the registry if it doesn’t exist

The following method will be used for when we start making some sub-classes! It is just a little helper function to parse the property name.

In the next article we will make a subclass that we can use in a .NET program.