Class Gs1
Reads GS1 element strings from their human-readable form, such as (01)09501101530003(17)261231(10)AB12, and checks each
against the GS1 General Specifications: the AI is defined, the characters and lengths fit it, and check digits, dates and times
are right. GS1-128, GS1 Data Matrix and GS1 QR encode the result.
public static class Gs1
- Inheritance
-
Gs1
- Inherited Members
Examples
// Each element string is checked: the AI, the length, the GTIN's check digit, the date.
IReadOnlyList<Gs1ElementString> elements = Gs1.Parse("(01)09501101530003(17)261231(10)AB12");
Barcode label = Barcode.Gs1Code128(elements);
// Mistakes say what is wrong.
if (!Gs1.TryParse("(01)09501101530004", out _))
{
Console.WriteLine("(01) has a wrong check digit");
}
Methods
Parse(string)
Reads element strings written with each AI in parentheses. A parenthesis inside a data field is written with a backslash
before it, (.
public static IReadOnlyList<Gs1ElementString> Parse(string text)
Parameters
textstringThe element strings, such as
(01)09501101530003(10)AB12.
Returns
- IReadOnlyList<Gs1ElementString>
The element strings in order.
Exceptions
- FormatException
The text is not element strings, or one does not fit its AI; the message says which and how.
TryParse(string?, out IReadOnlyList<Gs1ElementString>?)
Reads element strings written with each AI in parentheses, without throwing.
public static bool TryParse(string? text, out IReadOnlyList<Gs1ElementString>? elements)
Parameters
textstringThe element strings, such as
(01)09501101530003(10)AB12.elementsIReadOnlyList<Gs1ElementString>The element strings in order, or null.