I'm writing a DLL that will expose a method like this:
public static void Convert(string inputFile, string outputFile, FileType fileType)
At the moment, FileType is an enum that is exposed like this:
public enum FileType
{
ConvertClassOne,
ConvertClassTwo,
ConvertClassThree
}
This will represent each class that can convert a given type of file. I'll have several different classes based on an interface, each of which can process a particular type of file.
Instead of having an enum like I have above, where I have to change it manually each time I add a class so that the calling program can tell me which file type they're giving me, I'd like to expose an enum that automatically changes itself based on the classes in my project that have a given attribute.
So if I add a class with a given attribute:
[SomeAttribute]
public class NewClassAdded()
{
}
the FileType enum will pick this up and the calling program will be able to see
FileType.NewClassAdded
without me having to change anything else by hand. I'm pretty sure that Reflection will allow me to write a method that returns the name of each class with the given attribute, but I'm not sure exactly how, nor do I know how I would then expose these names as an enum.
Thanks,
Andrew