-1

I have a library with several text files as embedded resources like the following photo:

enter image description here

by running following line we have a string with the content of text file

Properties.Resources.CanadianCities

we need to know the name of the embedded resource ( CanadianCities ). so, in future, I added a new text file to embedded resource and I update my packages (UKCitites.txt). I want a dictionary in my DLL to cache the value of all text files (the text files are embedded resources). So, I do need the dictionary dynamically fetch the new embedded file.

  • Key: embedded file name
  • Value: the content of file
Mahdi
  • 1,777
  • 4
  • 24
  • 48

1 Answers1

1

If you are getting your resources from member properties of the Properties.Resources class, and all the resources that you need are exposed, then you can create a dictionary of them with this LINQ:

using System;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;

Dictionary<string, object> resourceDictionary = typeof(Properties.Resources)
        .GetProperties
            (
                BindingFlags.Static
              | BindingFlags.Public
            )
        .ToDictionary
            (
                p => p.Name, 
                p => p.GetValue(null) 
            );
John Wu
  • 50,556
  • 8
  • 44
  • 80