Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to prevent certain conversions? #123

Open
rkosafo opened this issue Jun 2, 2017 · 4 comments
Open

Is there a way to prevent certain conversions? #123

rkosafo opened this issue Jun 2, 2017 · 4 comments

Comments

@rkosafo
Copy link

rkosafo commented Jun 2, 2017

Values likes 001, 1234, etc in my configuration ends up automatically as TimeSpan. Is there a way to prevent this? I tried quoting them but it made no difference.

@vasily-kirichenko
Copy link
Contributor

Remove " or ' around them. Instead of foo: "001" write foo: 001.

@rkosafo
Copy link
Author

rkosafo commented Jun 2, 2017

Removing the " or ' around 001 makes it a float

  branchCode: 1 //int
  branchCode: 01 //float
  branchCode: 001 //float
  branchCode: '1'  //timespan
  branchCode: '01' //timespan
  branchCode: '001' //timespan

@alex-piccione
Copy link

alex-piccione commented Feb 27, 2019

I have a similar problem.
CustomerId: 66123

I want load it as string. It is always recognized as TimeSpan.
I tried to use:

  • CustomerId: 66123 -> ok, this should be recognized as number
  • CustomerId: "66123"
  • CustomerId: '66123'
  • CustomerId: !!str 66123
  • CustomerId: |
    66123
  • CustomerId: >
    66123

@alex-piccione
Copy link

alex-piccione commented Mar 5, 2019

I was able to read "001" and "66123" as a strings using the constructor with inferTypesFromString set to false:

ValueA: "001"
ValueB: !!str 001
type Configuration = YamlConfig<"configuration.yaml">
// value is loaded as TimeSpan 

type Configuration2 = YamlConfig<"configuration.yaml", true, "", false>
// value is loaded as string

The intellisense sometime shows the previous "logic" (TimeSpan) but at runtime it works. Rename the "Configuration" type temporary make it reload the new type and showing the correct type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants