Table of Contents

Class XmpArray

Namespace
Egami.Metadata
Assembly
Egami.dll

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

kind XmpArrayKind

Bag, sequence or alternative.

Properties

Count

Gets the number of items.

public int Count { get; }

Property Value

int

this[int]

Gets item index: a string, an XmpStruct or an XmpArray.

public object this[int index] { get; }

Parameters

index int

The index, from 0.

Property Value

object

The item.

Exceptions

ArgumentOutOfRangeException

index is not below Count.

Kind

Gets whether the array is a bag, a sequence or alternatives.

public XmpArrayKind Kind { get; }

Property Value

XmpArrayKind

Texts

Gets the simple items as text, in order; structures and nested arrays are left out.

public IReadOnlyList<string> Texts { get; }

Property Value

IReadOnlyList<string>

Methods

Add(XmpArray)

Adds a nested array; one that already belongs elsewhere is copied.

public void Add(XmpArray item)

Parameters

item XmpArray

The array.

Add(XmpStruct)

Adds a structure; one that already belongs elsewhere is copied.

public void Add(XmpStruct item)

Parameters

item XmpStruct

The structure.

Add(string)

Adds a simple value.

public void Add(string item)

Parameters

item string

The 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

language string

The 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

index int

The 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

kind XmpArrayKind

Bag or sequence.

items IEnumerable<string>

The texts.

Returns

XmpArray

The array.

RemoveAt(int)

Removes item index.

public void RemoveAt(int index)

Parameters

index int

The 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)

Parameters

language string

The language.

text string

The text.