Fix GetAttributeOfType method: add check for empty member info to prevent null reference exceptions

This commit is contained in:
a.beging@eas-solutions.de
2026-05-12 10:07:01 +02:00
parent c6178ecacd
commit bf69880d5f

View File

@@ -34,6 +34,7 @@ namespace FoodsharingSiegen.Contracts.Helper
{
var type = enumVal.GetType();
var memInfo = type.GetMember(enumVal.ToString());
if (memInfo.Length == 0) return null;
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
return attributes.Length > 0 ? (T)attributes[0] : null;
}