ParserFactory Class
Definition
Provides access to factory methods that are tailored for parsing operations adhering IParser and IConfigurableParser<TOptions>.
public static class ParserFactory
- Inheritance
-
ParserFactory
Examples
The following example demonstrates parsing a GUID string, a Base64-encoded value, and a URI string using the factory methods provided by ParserFactory. Each parser is created via a dedicated factory method and then invoked to produce a strongly typed result.
using System;
using Cuemon.Text;
namespace Cuemon.Text;
public class ParserFactoryExample
{
public void Demonstrate()
{
var guidParser = ParserFactory.FromGuid();
var result = guidParser.Parse("6B29FC40-CA47-1067-B31D-00DD010662DA");
Console.WriteLine($"Parsed GUID: {result}");
var base64Parser = ParserFactory.FromBase64();
var bytes = base64Parser.Parse("SGVsbG8gV29ybGQ=");
Console.WriteLine($"Base64 decoded bytes: {bytes.Length}");
var uriParser = ParserFactory.FromUri();
var uri = uriParser.Parse("https://example.com/resource");
Console.WriteLine($"Parsed URI: {uri}");
}
}
Methods
| Name | Description |
|---|---|
| CreateConfigurableParser<TOptions>(Func<string, Type, Action<TOptions>, object>) | Creates an IConfigurableParser<TOptions> implementation from the specified |
| CreateConfigurableParser<TResult, TOptions>(Func<string, Action<TOptions>, TResult>) | Creates an IConfigurableParser<TResult, TOptions> implementation from the specified |
| CreateParser(Func<string, Type, object>) | Creates an IParser implementation from the specified |
| CreateParser<TResult>(Func<string, TResult>) | Creates an IParser<TResult> implementation from the specified |
| FromBase64() | Creates a parser that converts a string, represented in base-64 digits, to its equivalent byte array. |
| FromBinaryDigits() | Creates a parser that converts a string, represented in binary digits, to its equivalent byte array. |
| FromEnum() | Creates a parser that converts a string to its equivalent Enum. |
| FromGuid() | Creates a parser that converts a string to its equivalent Guid. |
| FromHexadecimal() | Creates a parser that converts a string, represented in hexadecimal digits, to its equivalent byte array. |
| FromObject() | Creates a parser that converts a string to an Object of a particular type. |
| FromProtocolRelativeUri() | Creates a parser that converts a string, represented as a protocol relative URL, to its equivalent Uri. |
| FromUri() | Creates a parser that converts a string, represented as an URL, to its equivalent Uri. |
| FromUriScheme() | Creates a parser that converts a string, represented as an URI scheme, to its equivalent UriScheme. |
| FromUrlEncodedBase64() | Creates a parser that converts a string, represented in URL-safe base-64 digits, to its equivalent byte array. |
| FromValueType() | Creates a parser that converts a string, represented as a simple input type, to its equivalent bool, byte, int, long, double, float, DateTime or Guid. |