Class XmpStruct
An XMP structure: named fields, each a simple value (string), an XmpArray or another XmpStruct, such as Iptc4xmpCore:CreatorContactInfo. XmpData holds its top-level properties the same way.
public class XmpStruct
- Inheritance
-
XmpStruct
- Derived
- 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
XmpStruct()
Creates an empty structure.
public XmpStruct()
Properties
Count
Gets the number of fields.
public int Count { get; }
Property Value
Names
Gets the names of the fields, in order.
public IReadOnlyList<XmpName> Names { get; }
Property Value
Methods
Copy()
Returns an independent copy.
public XmpStruct Copy()
Returns
- XmpStruct
The copy.
GetText(XmpName)
Returns a field as text: a simple value as it is, a language alternative's x-default item (else its first), an ordered or unordered array's first item; null when there is no text to give.
public string? GetText(XmpName name)
Parameters
nameXmpNameThe field.
Returns
- string
The text.
Remove(XmpName)
Removes a field.
public bool Remove(XmpName name)
Parameters
nameXmpNameThe field.
Returns
- bool
Whether it was there.
Set(XmpName, XmpArray)
Sets a field to an array, replacing what was there. An array that already belongs elsewhere is copied.
public void Set(XmpName name, XmpArray value)
Parameters
Set(XmpName, XmpStruct)
Sets a field to a structure, replacing what was there. A structure that already belongs elsewhere is copied.
public void Set(XmpName name, XmpStruct value)
Parameters
Set(XmpName, string)
Sets a field to a simple value, replacing what was there.
public void Set(XmpName name, string value)
Parameters
TryGet(XmpName, out object?)
public bool TryGet(XmpName name, out object? value)
Parameters
Returns
- bool
Whether the field is there.
TryGetDate(XmpName, out DateTimeOffset)
Returns a simple value written as an XMP date (ISO 8601: YYYY, YYYY-MM, YYYY-MM-DD, then optionally Thh:mm, :ss and fractions, and a zone); a date with no zone is taken as UTC.
public bool TryGetDate(XmpName name, out DateTimeOffset value)
Parameters
nameXmpNameThe field.
valueDateTimeOffsetThe date.
Returns
- bool
Whether the field is a date.
TryGetInt(XmpName, out long)
Returns a simple value as an integer, if it is one.
public bool TryGetInt(XmpName name, out long value)
Parameters
Returns
- bool
Whether the field is an integer.
TryGetRational(XmpName, out double)
Returns a simple value written as a rational ("28/10") or a decimal number ("2.8"), as a number.
public bool TryGetRational(XmpName name, out double value)
Parameters
Returns
- bool
Whether the field is a number.