ControlUtils: Cleanup SelectItem() method and use accordingly

This commit is contained in:
2024-03-18 17:55:27 +01:00
parent 51e345f1fd
commit 2f3524db9d
20 changed files with 181 additions and 194 deletions

View File

@ -435,17 +435,17 @@ namespace Elwig.Helpers {
return client;
}
public static int GetEntityIdentifier(object? obj) {
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 {
return null;
} else if (obj is IEnumerable list && obj is not string) {
var arr = list.Cast<object>().Select(GetEntityIdentifier).ToArray();
return ((IStructuralEquatable)arr).GetHashCode(EqualityComparer<int?>.Default);
} else if (obj.GetType().GetCustomAttribute(typeof(PrimaryKeyAttribute), true) is PrimaryKeyAttribute pkAttr) {
var pk = pkAttr.PropertyNames.Select(name => obj.GetType().GetProperty(name)!.GetValue(obj)?.GetHashCode() ?? 0).ToArray();
return ((IStructuralEquatable)pk).GetHashCode(EqualityComparer<int>.Default);
} else {
return obj.GetHashCode();
}
}
}