Manifest Resource Streams
Manifest Resource Streams allow you to include data from files as byte arrays in your code. An example of its use is in the ZMachine Demo.
How to use
- Set for the file you want to use
Build As: Embedded Resource
using the File Properties window in VS. - In the code, reference the file using the following format (a static byte array with the attribute):
[ManifestResourceStream(ResourceName = "{project_name}.{path}.{to}.{filename_with_extension}")]
static byte[] file;
The field must be static but the name of the field (file) can be changed. You will also need to add using IL2CPU.API.Attribs;
to the code.
For example, if the project is called Kernel and the file is Data\Text.txt
, then ResourceName = "Kernel.Data.Text.txt"
.
- To access the data simply read from the byte array defined.
string fileContent = System.Text.Encoding.UTF8.GetString(file); //convert the byte array to string (assuming text data)
Console.WriteLine(fileContent); //write it out
Last updated on 28 July 2023.