What can a person use instead of enum for a collective line containing intellisense?

Enumeration is currently being used for the list of file names in the application to enable intellisense and to ensure that the file name is one of the existing files (enum prevents typos and must remember each file name verbatim). The list contains 107 files. To get the name of the audio file, the ToString () method is used to enumerate.

Now a situation arises when file names should be added based on the result of the database call. This is not possible with an enumeration and will require a lot of restructuring of the application to implement (changing all methods that accept an enumeration to take a string).

What was to be done in the first place or is this listing the best option for this use case?

+4
source share
3 answers

I'm not quite sure about the use, but one of them is resource files. You will get intellisense and an additional bonus, allowing you to change the file names for each localization.

See here for an example.

+8
source

One way to do this would be to simply list each file as a string constant. But it is disappointing to add new content, and if you ever want to add new sounds, you will have to recompile and redistribute the entire application.

Instead, consider listing your audio files in a single data file (XML, maybe?). Inside your program, import the data as a string key, a dictionary with string values, where your keys are the name of the sound, and the values โ€‹โ€‹are the names of the files. Create a wrapper class to hold the dictionary so you can handle errors gracefully, and voilร ! You have access to your sounds, and you can add and remove sounds outside of the code itself.

In addition, when you make your call in the database, all you have to do is add additional audio data to the dictionary.

0
source

You might need to create a static class with constant members.

static class FileNames { public const string FirstFileName = "FirstFileName.txt"; //and so on } 

If for the part of the database (which is not designed and leaves room for guesswork), you can use the T4 template, which generates a class that has a list of file names declared in the form above. The T4 template can make a database call during development using regular ADO.NET code, then the query result can be used to display file names and constant members.

It is very useful to open T4: check this link: http://msdn.microsoft.com/en-us/library/bb126445.aspx .

0
source

Source: https://habr.com/ru/post/1443744/


All Articles