WPF: Add custom type object to Settings

Just add such code to existing Settings.cs file (Settings.settings -> View code):

		[global::System.Configuration.UserScopedSettingAttribute()]
		[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
		[global::System.Configuration.DefaultSettingValueAttribute("")]
		public List< (DateTime, decimal profitLoss)> ProfitLosses
		{
			get => (List< (DateTime, decimal profitLoss)>)(this["ProfitLosses"]);
			set => this["ProfitLosses"] = value;
		}

Here line

[global::System.Configuration.DefaultSettingValueAttribute("")]


allows to initialize object with default value (with empty List in this case) instead of set it null

Leave a Reply

  

  

  

www.000webhost.com