Class XmpArray
An XMP array: items in order, each a simple value (string), an XmpStruct or another XmpArray, with a language for the items of a language alternative.
public sealed class XmpArray
- Inheritance
-
XmpArray
- Inherited Members
Examples
XmpData xmp = new()
{
Title = "Harbour at dawn",
Creators = ["A. Photographer"],
Keywords = ["harbour", "Bergen"],
Rating = 4,
};
// Any property, by namespace URI and local name; structures and arrays nest.
XmpStruct contact = new();
contact.Set(new XmpName(XmpNamespaces.IptcCore, "CiEmailWork"), "photo@example.com");
xmp.Set(new XmpName(XmpNamespaces.IptcCore, "CreatorContactInfo"), contact);
if (xmp.TryGet(new XmpName(XmpNamespaces.DublinCore, "title"), out object? title) && title is XmpArray languages)
{
languages.SetLanguage("nb-NO", "Havn ved daggry");
}
ReadOnlyMemory<byte> packet = xmp.ToBytes(); // canonical RDF/XML with padding
Constructors
XmpArray(XmpArrayKind)
Creates an empty array.
public XmpArray(XmpArrayKind kind)
Parameters
kindXmpArrayKindBag, sequence or alternative.
Properties
Count
Gets the number of items.
public int Count { get; }
Property Value
this[int]
public object this[int index] { get; }
Parameters
indexintThe index, from 0.
Property Value
- object
The item.
Exceptions
- ArgumentOutOfRangeException
indexis not below Count.
Kind
Gets whether the array is a bag, a sequence or alternatives.
public XmpArrayKind Kind { get; }
Property Value
Texts
Gets the simple items as text, in order; structures and nested arrays are left out.
public IReadOnlyList<string> Texts { get; }
Property Value
Methods
Add(XmpArray)
Adds a nested array; one that already belongs elsewhere is copied.
public void Add(XmpArray item)
Parameters
itemXmpArrayThe array.
Add(XmpStruct)
Adds a structure; one that already belongs elsewhere is copied.
public void Add(XmpStruct item)
Parameters
itemXmpStructThe structure.
Add(string)
Adds a simple value.
public void Add(string item)
Parameters
itemstringThe text.
Clear()
Removes every item.
public void Clear()
Copy()
Returns an independent copy.
public XmpArray Copy()
Returns
- XmpArray
The copy.
GetLanguage(string)
Returns the text for a language, compared without case; null when there is none.
public string? GetLanguage(string language)
Parameters
languagestringThe language, such as "x-default", "en" or "nb-NO".
Returns
- string
The text.
LanguageAt(int)
Returns item index's language (xml:lang), or null.
public string? LanguageAt(int index)
Parameters
indexintThe index, from 0.
Returns
- string
The language.
Of(XmpArrayKind, params IEnumerable<string>)
Creates an array of simple values.
public static XmpArray Of(XmpArrayKind kind, params IEnumerable<string> items)
Parameters
kindXmpArrayKindBag or sequence.
itemsIEnumerable<string>The texts.
Returns
- XmpArray
The array.
RemoveAt(int)
Removes item index.
public void RemoveAt(int index)
Parameters
indexintThe index, from 0.
SetLanguage(string, string)
Sets the text for a language, replacing it or adding it; x-default goes first, as XMP requires.
public void SetLanguage(string language, string text)