Class IdentifierDefinition
Base class for defining identifiers in structured data formats, including validation rules.
Inheritance
Namespace: IronBarCode
Assembly: IronBarCode.dll
Syntax
public class IdentifierDefinition : Object
When a structured barcode payload such as a GS1 string needs to be split into named fields, IdentifierDefinition is the rule that describes one of those fields. Structured formats prefix each value with an identifier code that says what the value is and how long it runs, and a definition captures that contract for a single identifier so the parser knows where one field ends and the next begins. A developer works with these definitions when reading or validating application-identifier data rather than treating a barcode as one opaque string.
A definition states the shape of its field. Identifier is the code that introduces the field, Description is a human-readable label for it, and Format describes the expected content. Length is expressed by Length for fixed-width fields, with IsVariableLength flagging fields that can vary and MaxLength capping how far a variable field may run. These together let the parser carve a payload into the right pieces without guessing.
Validation rides on Validator, a Func<string, ValidationResult> that checks a candidate value and returns a ValidationResult reporting whether it is well formed. A developer reads these properties to understand how a field is recognized and constrained, and the resulting ParsedElement objects carry the data each definition extracted. Treat the definition as the read-only description of a field's rules. The checksum and format validation how-to walks through validating structured values, and the output data formats how-to shows how parsed fields are surfaced.
using IronBarCode;
Console.WriteLine($"{definition.Identifier}: {definition.Description}");
ValidationResult check = definition.Validator(candidate);
Console.WriteLine(check.IsValid);The reading barcodes tutorial covers the wider read and parse workflow.
Constructors
IdentifierDefinition(String, Int32, String, String, Func<String, ValidationResult>)
Initializes a new instance of the IdentifierDefinition class.
Declaration
public IdentifierDefinition(string identifier, int length, string description, string format, Func<string, ValidationResult> validator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | identifier | The identifier string. |
| System.Int32 | length | The length of the data (negative for variable length). |
| System.String | description | Description of the identifier. |
| System.String | format | Expected format of the data. |
| System.Func<System.String, ValidationResult> | validator | Optional validator function. Uses default validator if null. |
Properties
Description
Description of the identifier.
Declaration
public string Description { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Format
Expected format of the data.
Declaration
public string Format { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Identifier
Identifier string that this definition represents.
Declaration
public string Identifier { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
IsVariableLength
Gets a value indicating whether this identifier represents variable-length data.
Declaration
public bool IsVariableLength { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Length
Length of the data element. Negative values indicate variable length.
Declaration
public int Length { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
MaxLength
Maximum length of the data (absolute value of Length property).
Declaration
public int MaxLength { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Validator
Validator function for this identifier.
Declaration
public Func<string, ValidationResult> Validator { get; }
Property Value
| Type | Description |
|---|---|
| System.Func<System.String, ValidationResult> |