0

I want to have a property in my App.xaml.cs which look like:

private static Settings _settings = null;
public static Settings AppSettings
{
   get
   {
      if(_settings == null)
         _settings = await Settings.Deserialize();

      return _settings;
   }
}

In the Settings.Deserialize() I am reading setting from file so it have next signature:

public static async Task<Settings> Deserialize() { ... }

I can not use await in the property. But what is the good solution in this case ?

ceth
  • 42,340
  • 57
  • 170
  • 277

1 Answers1

0

Make getter and setter functions instead of a property. You shouldn't use properties for things that have side effects in the first place (no saving to or from storage/db/web service, etc.)

linkerro
  • 5,174
  • 3
  • 23
  • 28