Skip to content

Commit 4e5f61d

Browse files
committed
Skip Settings event if no property changes
1 parent b9f010a commit 4e5f61d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

StabilityMatrix.Core/Services/SettingsManager.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ void OnSourcePropertyChanged(object? sender, PropertyChangedEventArgs args)
193193
if (args.PropertyName != sourcePropertyPath)
194194
return;
195195

196+
// If TValue is a primitive type, check if there are changes first.
197+
// If not, skip saving and property changed event.
198+
if (typeof(TValue).IsPrimitive || typeof(TValue).IsEnum)
199+
{
200+
var settingsValue = settingsAccessor.Get(Settings);
201+
var sourceValue = sourceInstanceAccessor.Get();
202+
if (EqualityComparer<TValue>.Default.Equals(settingsValue, sourceValue))
203+
{
204+
/*logger.LogTrace(
205+
"[RelayPropertyFor] {SourceType:l}.{SourceProperty:l} -> Settings.{SettingsProperty:l} (<No Changes>)",
206+
sourceTypeName,
207+
sourcePropertyPath,
208+
settingsPropertyPath
209+
);*/
210+
return;
211+
}
212+
}
213+
196214
logger.LogTrace(
197215
"[RelayPropertyFor] {SourceType:l}.{SourceProperty:l} -> Settings.{SettingsProperty:l}",
198216
sourceTypeName,

0 commit comments

Comments
 (0)