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
  • 44,198
  • 62
  • 180
  • 289

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,318
  • 3
  • 25
  • 29