Gs1Element Class
Represents a GS1 element string: an application identifier (AI) and the data it qualifies, such as AI 01 (GTIN) and 09521234543213.
public sealed class Gs1ElementRemarks
The data does not include the parentheses of the human-readable interpretation: they are printed under the bars but are not encoded. By default, the application identifier and the data are checked against the syntax rules every GS1 element follows. Use Gs1ValidationMode.Dictionary to also check them against the GS1 dictionary of application identifiers (the format of the data of each identifier, its check digits, dates, ...), and Gs1Element.ValidateAssociations to check the identifiers that must or must not be used together.
Constructors
| Name | Description |
|---|---|
| Gs1Element(string, string) | Initializes a new instance of the Gs1Element class, checked against the syntax rules of element strings. |
| Gs1Element(string, string, Gs1ValidationMode) | Initializes a new instance of the Gs1Element class. |
Gs1Element overloads
Gs1Element(string, string)
Gs1Element.csInitializes a new instance of the Gs1Element class, checked against the syntax rules of element strings.
Parameters
applicationIdentifierstring- The application identifier: 2 to 4 digits, without parentheses.
valuestring- The data: characters of the GS1 AI encodable character set 82 (letters, digits and
!"%&'()*+,-./:;<=>?_), and#for the application identifier8010. The application identifiers whose data has a predefined length (00to04,11to20,31nnto36nnand41n) require digits of that length.
Exceptions
ArgumentException- The application identifier or the data is not valid.
Gs1Element(string, string, Gs1ValidationMode)
Gs1Element.csInitializes a new instance of the Gs1Element class.
public Gs1Element(string applicationIdentifier, string value, Gs1ValidationMode validationMode)Parameters
applicationIdentifierstring- The application identifier: 2 to 4 digits, without parentheses.
valuestring- The data that the application identifier qualifies.
validationModeGs1ValidationMode- The rules the application identifier and the data are checked against.
Exceptions
ArgumentException- The application identifier or the data is not valid, or, with
Gs1ValidationMode.Dictionary, the application identifier is not in the GS1 dictionary or the data does not match its format.
Example
// The syntax rules accept any data of 14 digits for a GTIN
var element = new Gs1Element("01", "09521234543214");
Assert.Equal("(01)09521234543214", element.ToString());
// The GS1 dictionary also checks the check digit, the dates, the country codes, ...
var exception = Assert.Throws<ArgumentException>("value", () => new Gs1Element("01", "09521234543214", Gs1ValidationMode.Dictionary));
Assert.Contains("The numeric check digit is incorrect.", exception.Message);
var gtin = new Gs1Element("01", "09521234543213", Gs1ValidationMode.Dictionary);
var expiry = new Gs1Element("17", "250100", Gs1ValidationMode.Dictionary); // day 00: the end of the month
var barcode = Barcode.CreateGs1128(gtin, expiry);
Assert.Equal("(01)09521234543213(17)250100", barcode.Text);Properties
| Name | Description |
|---|---|
| ApplicationIdentifier | Gets the application identifier, such as 01. |
| Value | Gets the data that the application identifier qualifies. |
ApplicationIdentifier
Gs1Element.csValue
Gs1Element.csMethods
| Name | Description |
|---|---|
| ToString() | Returns the human-readable interpretation of the element string, such as (01)09521234543213. |
| ValidateAssociations(ReadOnlySpan<Gs1Element>) | Checks the associations of application identifiers that the GS1 dictionary defines: the identifiers that an identifier requires, such as a batch number (10) that requires a GTIN (01), and the identifiers that cannot be used together, such as a GTIN (01) and the GTIN of the contained items (02). An application identifier cannot appear twice with different data. |
ToString()
Gs1Element.csValidateAssociations(ReadOnlySpan<Gs1Element>)
Gs1Element.csChecks the associations of application identifiers that the GS1 dictionary defines: the identifiers that an identifier requires, such as a batch number (10) that requires a GTIN (01), and the identifiers that cannot be used together, such as a GTIN (01) and the GTIN of the contained items (02). An application identifier cannot appear twice with different data.
public static void ValidateAssociations(params scoped ReadOnlySpan<Gs1Element> elements)Parameters
elementsReadOnlySpan<Gs1Element>- The elements marked on an item. Pass the elements of every barcode of the item: an identifier may require an identifier encoded in another barcode. The application identifiers that are not in the dictionary have no rules.
Exceptions
ArgumentExceptionelementscontainsnull, a required application identifier is missing, two application identifiers cannot be used together, or an application identifier appears twice with different data.
Example
var gtin = new Gs1Element("01", "09521234543213", Gs1ValidationMode.Dictionary);
var batch = new Gs1Element("10", "ABC123", Gs1ValidationMode.Dictionary);
Gs1Element.ValidateAssociations(gtin, batch);
// A batch number qualifies a trade item: it requires a GTIN
Assert.Throws<ArgumentException>("elements", () => Gs1Element.ValidateAssociations(batch));