• Home
  • Install
  • Cosmos Website
  • Articles
  • Cosmos
  • X#
  • IL2CPU
Show / Hide Table of Contents
  • Getting Started
  • Compiler
  • Change Log
  • Debugger
    • Debug Commands
  • Installation
    • User Kit
    • Dev Kit
    • Running
  • Kernel
    • Levels
    • Plugs
    • Startup
    • OnBoot
    • Graphics
    • Virtual File System
    • Network
    • Resource Files
    • Memory Management and Garbage Collection
    • Audio
  • Reference
    • x86
  • Tests
    • Test Runner

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

  1. Set for the file you want to use Build As: Embedded Resource using the File Properties window in VS. image
  2. 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".

  1. 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.

  • Improve this Doc
☀
☾
In This Article
Back to top
☀
☾