C
C#3y ago
WarChortle

Creating a interface for a template engine for multiple different types

I created a very basic template engine to scan a string for a token and replace it. I am struggling to come up with an interface that can be used by various types to define what properties in it need to be passed through the template engine. The idea was to create a base class that any object could inherit from and by calling a method on that class all of the string properties(or all the defined string properties) could be run through the template engine. But I cant find a good way to do that. I looked into using reflection but wasn't able to get the value of the property. Any ideas on how to implement this, or on another approach.
1 Reply
TheBoxyBear
TheBoxyBear3y ago
Since it's a feature, the method should be defined in an interface. For the properties in the string, you could define an attribute to mark which properties to insert. For getting a value, simply PropertyInfo.GetValue(instance) (not static) Getting the property infos from typeof().GetProperties() or instance.GetType() to get the runtime type
Want results from more Discord servers?
Add your server