Is there a simpler syntax for accessing resources embedded in an assembly?

Now I have several classes in the class:

string upgrade_file 
    = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(
        Assembly.GetExecutingAssembly().GetName().Name 
        + ".schemas.template.db_upgrades.txt")
        ).ReadToEnd();

I can write a wrapper function to simplify access to embedded resources (and I will, if necessary), but is there an easier or more elegant way to access them using .Net?

For example, it seems strange to me that GetManifestResourceStream (...) is not static. Another example: is there some method that returns a string and not a stream for text files?

UPDATE 1 :

To be clear, I have text files in subdirectories, and I want to:

  • These files remain separate files (for example, so that they can be controlled separately)
  • These files remain embedded resources, that is, compiled using the assembly.

, : enter image description here

2:

- , .

, , - :

/// <summary>
/// Get the content of a text file embedded in the enclosing assembly.
/// </summary>
/// <param name="resource">The "path" to the text file in the format 
/// (e.g. subdir1.subdir2.thefile.txt)</param>
/// <returns>The file content</returns>
static string GetEmbeddedTextFile(string resource)
{
    return new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(
        Assembly.GetExecutingAssembly().GetName().Name + "." + resource)).ReadToEnd();
}
+3
4

Resource1, TXT .

string str = Resource1.TxtFile;
byte[] file = Resource1.BinaryFile;
0

, VS, Resource.resx, , ? - -.

Rsources.resx , , , .

0

, Assembly, , .

, , , " ", , :

public static class Extensions
{
    public static string ReadTextResource(this Assembly asm, string resName)
    {
        string text;
        using (Stream strm = asm.GetManifestResourceStream(resName))
        {
            using (StreamReader sr = new StreamReader(strm))
            {
                text = sr.ReadToEnd();
            }
        }
        return text;
    }
}

DLL , , , :

        string content = Assembly.GetExecutingAssembly().ReadTextResource(myResourceName);

( , )

0
string upgrade_file  = Resources.db_upgrades.txt
-2

All Articles