Giter VIP home page Giter VIP logo

Comments (2)

oliversweb avatar oliversweb commented on July 23, 2024

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.

davidwhitney avatar davidwhitney commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.