AdministrationWindow: Use GetHashCode() to compare default/original values
This commit is contained in:
@ -18,7 +18,9 @@ using System.Text.Json.Nodes;
|
||||
using System.IO;
|
||||
using MailKit.Net.Smtp;
|
||||
using MailKit.Security;
|
||||
using OpenTK.Compute.OpenCL;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
public static partial class Utils {
|
||||
@ -432,5 +434,19 @@ namespace Elwig.Helpers {
|
||||
await client.AuthenticateAsync(username, password);
|
||||
return client;
|
||||
}
|
||||
|
||||
public static int GetEntityIdentifier(object? obj) {
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
} else if (obj is IEnumerable list) {
|
||||
var arr = list.Cast<object>().Select(o => GetEntityIdentifier(o)).ToArray();
|
||||
return ((IStructuralEquatable)arr).GetHashCode(EqualityComparer<int>.Default);
|
||||
} else if (obj.GetType().GetCustomAttribute(typeof(PrimaryKeyAttribute), false) is not PrimaryKeyAttribute pkAttr) {
|
||||
return obj.GetHashCode();
|
||||
} else {
|
||||
var pk = pkAttr.PropertyNames.Select(name => obj.GetType().GetProperty(name)!.GetValue(obj)?.GetHashCode() ?? 0).ToArray();
|
||||
return ((IStructuralEquatable)pk).GetHashCode(EqualityComparer<int>.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user