static class · System
Resources
public static class Resources
- Tipo
- static class
- Espacio de nombres
- System
- Ensamblado
- System.Core
- Acceso
- public, static, abstract
- Archivo fuente
Resources.ant
Herencia
- Clases base
-
AnyResources
Métodos
Adds a resource at run time (a later one with the same name replaces it, and hides a built-in one).
Whether the program has resource name.
The bytes of resource name (a copy), or null when there is none.
ReadText(str name) : str?
#
The text (UTF-8) of resource name, or null when there is none.
View(str name) : ResourceData?
#
Resource name read in place (no copy), or null when there is none.
Names() : str[]
#
The names of every resource: the built-in ones in build order, then the installed ones.
Miembros privados e internos (9)
Miembros heredados (5)
GetTypemétodo de AnyUndescribedmétodo de AnyToStringmétodo de AnyHashmétodo de Anydestroymétodo de Any
Código fuente
Resources en Antril, descompilado a partir de su Larva HIR.
// System.Resources — System.Core (decompiled from Larva HIR)
into namespace System
{
public static class Resources
{
Dictionary<str, i32> builtIn;
Dictionary<str, u8[]> installed;
List<str> installedNames;
extern("$resources.count") Count() : i32;
extern("$resources.name") NameOf(i32 index) : u8[];
extern("$resources.bytes") BytesOf(i32 index) : u8[];
extern("$resources.length") LengthOf(i32 index) : i32;
unsafe extern("$resources.data") DataOf(i32 index) : u8*;
BuiltIn() : Dictionary<str, i32>
{
Dictionary<str, i32> map = new Dictionary<str, i32>();
loop (i32 i = 0..Count())
map[new str(NameOf(i))] = i;
return map;
}
public:
/// Adds a resource at run time (a later one with the same name replaces it, and hides a built-in one).
Install(str name, u8[] bytes)
{
if (!installed.ContainsKey(name))
installedNames.Add(name);
installed[name] = bytes;
}
/// Whether the program has resource `name`.
Has(str name) : bool => installed.ContainsKey(name) || builtIn.ContainsKey(name);
/// The bytes of resource `name` (a copy), or null when there is none.
Read(str name) : u8[]?
{
if (installed.ContainsKey(name))
return installed[name];
if (builtIn.ContainsKey(name))
return BytesOf(builtIn[name]);
return null;
}
/// The text (UTF-8) of resource `name`, or null when there is none.
ReadText(str name) : str?
{
if (Read(name) is u8[] bytes)
return new str(bytes);
return null;
}
/// Resource `name` read in place (no copy), or null when there is none.
View(str name) : ResourceData?
{
if (installed.ContainsKey(name))
{
u8[] bytes = installed[name];
i32 length = bytes.Length;
unsafe
{
u8* first = length == 0 ? DataOf(-1) : &bytes[0];
return new ResourceData(first, length);
}
}
if (builtIn.ContainsKey(name))
{
i32 index = builtIn[name];
unsafe
{
return new ResourceData(DataOf(index), LengthOf(index));
}
}
return null;
}
/// The names of every resource: the built-in ones in build order, then the installed ones.
Names() : str[]
{
List<str> names = new List<str>();
loop (i32 i = 0..Count())
names.Add(new str(NameOf(i)));
loop (i32 i = 0..installedNames.Count)
{
if (!builtIn.ContainsKey(installedNames[i]))
names.Add(installedNames[i]);
}
return names.ToArray();
}
}
}