Comments (2)
Firstly; I don't think there is an 'out of the box' converter for string
to Guid
so whatever string you read out of the config will not converter automatically to a Guid
, you will need a custom converter of type IConvertType
.
Secondly; a Guid
is a Value Type (Struct) so providing a null
as a default will not work, , you will still need a custom converter of type IConvertType
.
Try adding this converter;
public class CustomGuidConverter : IConvertType
{
public Type TargetType { get { return typeof(Guid); } }
public object Convert(string configurationValue)
{
return Guid.Parse(configurationValue);
}
}
Initialise it something like this;
new AppSettingsExtended(_underlyingConfiguration, null, new[] { new CustomGuidConverter() });
Then use it something like this;
_wrapper.AppSetting<Guid>("someGuidVal", whenConversionFailsInsteadOfThrowingDefaultException: () => Guid.Empty)
Or like this if you just want to capture missing key exceptions;
_wrapper.AppSetting<Guid>("someMissingGuidVal", whenKeyNotFoundInsteadOfThrowingDefaultException: () => Guid.Empty);
Or if you need a null
returned then use a nullable Guid
as the generic type;
_wrapper.AppSetting<Guid?>("someMissingGuidVal", whenKeyNotFoundInsteadOfThrowingDefaultException: () => null);
Hope that helps.
from system.configuration.abstractions.
Version 2.0.2.44 ports @oliversweb work in as default behaviour - this should now work OOTB <3
from system.configuration.abstractions.
Related Issues (10)
- Exception HOT 3
- Uri Converter HOT 4
- Mocking out configuration section HOT 2
- Mixed use of .NET and System.Configuration.Abstractions ConfigurationManager causes inconsistent behavior HOT 1
- Conversion to enum seems to fail after each redeploy + JITer warmup HOT 11
- "Source array was not long enough. Check srcIndex and length, and the array's lower bounds" HOT 5
- Reading appsettings.json in .net core? HOT 1
- License file is missing from the repo HOT 2
- Getting error Could not load file or assembly HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from system.configuration.abstractions.