C#: How to make sure a settings variable exists before attempting to use it from another assembly?

前端 未结 5 1900
忘了有多久
忘了有多久 2021-02-07 11:10

I have the following:

using CommonSettings = MyProject.Commons.Settings;

public class Foo
{
    public static void DoSomething(string str)
    {
        //How d         


        
5条回答
  •  灰色年华
    2021-02-07 11:44

    try
    {
        var x = Settings.Default[bonusMalusTypeKey]);
    }
    catch (SettingsPropertyNotFoundException ex)
    {
        // Ignore this exception (return default value that was set)
    }
    

提交回复
热议问题