Table of Contents

Enum GuidFormats

Namespace
Cuemon
Assembly
Cuemon.Kernel.dll

Specifies allowed GUID formats in parsing related methods.

[Flags]
public enum GuidFormats

Fields

Any = N | D | B | P | X

Specified any of the supported GUID formats (N,D,B,P,X).

B = 4

Specified the brace format (B) which consist of 32 digits separated by hyphens, enclosed in brackets, eg. {12345678-1234-1234-1234-123456789abc}.

D = 2

Specified the digit format (D) which consist of 32 digits separated by hyphens, eg. 12345678-1234-1234-1234-123456789abc.

N = 1

Specified the number format (N) which consist of 32 digits, eg. 12345678123412341234123456789abc.

P = 8

Specified the parenthesis format (P) which consist of 32 digits separated by hyphens, enclosed in parentheses, eg. (12345678-1234-1234-1234-123456789abc).

X = 16

Specified four hexadecimal values enclosed in braces (X) where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces.

Examples

The following example demonstrates how to use the flags enum to control which GUID formats are accepted during parsing.

using System;
using Cuemon; // for GuidFormats
using Cuemon.Text; // for ParserFactory, GuidStringOptions

namespace MyApp.Examples;

public class GuidFormatsExample
{
    public void Demonstrate()
    {
        var parser = ParserFactory.FromGuid();

        // Accept only digit (D) and brace (B) formats
        Guid g1 = parser.Parse("12345678-1234-1234-1234-123456789abc",
            o => o.Formats = GuidFormats.D | GuidFormats.B);
        Console.WriteLine(g1); // 12345678-1234-1234-1234-123456789abc

        Guid g2 = parser.Parse("{12345678-1234-1234-1234-123456789abc}",
            o => o.Formats = GuidFormats.D | GuidFormats.B);
        Console.WriteLine(g2);

        // TryParse with number format (N) - using Hyphens, so it would fail
        bool ok = parser.TryParse("12345678123412341234123456789abc", out Guid g3,
            o => o.Formats = GuidFormats.N);
        Console.WriteLine(ok); // True - only N is selected and input has no hyphens

        // Fail: brace format but only D selected
        ok = parser.TryParse("{12345678-1234-1234-1234-123456789abc}", out Guid g4,
            o => o.Formats = GuidFormats.D);
        Console.WriteLine(ok); // False

}
}