ControlUtils: Cleanup SelectItem() method and use accordingly
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user