Vostok.Configuration
HomeQuickstartConcepts and basicsBasic scenarios
  • Home
  • Quickstart
  • Concepts and basics
    • Settings nodes
      • Value nodes
      • Array nodes
      • Object nodes
    • Settings nodes merging
    • Settings nodes scoping
    • Binding nodes to models
    • Configuration sources
    • Configuration provider
    • Caching and performance
    • Error handling
  • Modules
    • Abstractions
    • Configuration
    • Sources
    • Sources.CC
    • Sources.Json
    • Sources.Yaml
    • Sources.Xml
    • Sources.Vault
    • Logging
    • Microsoft
  • Sources
    • Constant sources
    • Object source
    • XML sources
    • YAML sources
    • JSON sources
    • Vault source
    • ClusterConfig source
    • Command line source
    • Environment variables source
  • Binders
    • Primitives
    • Collections
    • Classes and structs
    • Constructor injection
  • Basic scenarios
    • Assign sources to types
    • Obtain settings from provider
    • Observe settings via provider
    • Print settings
    • Log settings updates
    • Log errors
    • Combine sources
    • Scope sources
    • Make settings secret
    • Make settings required
  • Advanced scenarios
    • Use name aliases
    • Use dynamic interfaces
    • Use shared provider instance
    • Use value substitutions
    • Nest sources
    • Freeze sources
    • Transform sources
    • Create custom sources
    • Apply custom validators
    • Apply custom binders
    • Apply source data to existing object
    • Print contents of a source
Powered by GitBook
On this page
  • Supported types
  • Parse method convention
  • Node requirements
  • Null node handling
  • Incorrect format handling
  • Related pages

Was this helpful?

Export as PDF
  1. Binders

Primitives

PreviousBindersNextCollections

Last updated 3 years ago

Was this helpful?

Primitive types are parsed from string values in .

Supported types

Type

Allowed format examples

string

Literally any string.

char

Literally any single character.

bool

true, True, TRUE

byte, sbyte

Anything built-in TryParse method can grok.

short, ushort

Anything built-in TryParse method can grok.

int, uint

Anything built-in TryParse method can grok.

long, ulong

Anything built-in TryParse method can grok.

float, double, decimal

1.23, 1,23, 5,12e2

Guid

Anything built-in TryParse method can grok.

Uri

http://example.com, example.com/some, /part/of/path

TimeSpan

00:12:34, 2 seconds, 500 ms, 1.5 days, 10s, 0.5 minutes

DateTime(Offset)

2018-03-14 15:09:26.535, 20050809T181142+0330

IPAddress

127.0.0.1, 2001:0db8:11a3:09d7:1f34:8a2e:07a0:765d

IPEndPoint

192.168.1.10:80

453453 (just bytes), 1 kb, 24.3 megabytes, 500 TB

500 (just bytes/sec), 200 kilobytes/second, 5 GB/sec, 80 mb/s

Encoding

utf-8, us-ascii

Enum types

Anything built-in TryParse method can grok.

Nullable structs

A valid value or null.

DataSize size = 50.Megabytes();
DataRate rate = size / 2.Seconds();

Parse method convention

There's also support for types that implement Parse or TryParse method with standard signature:

class/struct T 
{
    public static T Parse(string input) { ... }
    
    public static bool TryParse(string input, out T result) { ... }
}

Node requirements

Null node handling

Explicitly specified null string value has the same effect.

Incorrect format handling

Related pages

and are custom new types. They also provide factory extensions and operators:

This allows to use arbitrary types with string representation without resorting to .

or a container (array/object) node with a single value node child.

Default value for the type is used unless .

Parsing errors arising from incorrect value formats lead to binder failure and result in exceptions, even for optional members (see for more context).

value nodes
DataSize
DataRate
implementation of custom binders
Value node
explictly required
classes and structs
Binding nodes to models
DataSize
DataRate