Fix GetAttributeOfType method: add check for empty member info to prevent null reference exceptions
This commit is contained in:
@@ -34,6 +34,7 @@ namespace FoodsharingSiegen.Contracts.Helper
|
|||||||
{
|
{
|
||||||
var type = enumVal.GetType();
|
var type = enumVal.GetType();
|
||||||
var memInfo = type.GetMember(enumVal.ToString());
|
var memInfo = type.GetMember(enumVal.ToString());
|
||||||
|
if (memInfo.Length == 0) return null;
|
||||||
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
|
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);
|
||||||
return attributes.Length > 0 ? (T)attributes[0] : null;
|
return attributes.Length > 0 ? (T)attributes[0] : null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user