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

前端 未结 5 1903
忘了有多久
忘了有多久 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 12:00

    If you are using a SettingsPropertyCollection you have to loop and check which settings exists yourself it seems, since it doesn't have any Contains-method.

    private bool DoesSettingExist(string settingName)
    {
       return Properties.Settings.Default.Properties.Cast().Any(prop => prop.Name == settingName);
    }
    

提交回复
热议问题