diff --git a/VectoCommon/VectoCommon/Utils/Validation.cs b/VectoCommon/VectoCommon/Utils/Validation.cs index ebfe5f6b5d21df369c3ba563e091211e249aaae4..0f8a09e0fae001de5bdf70dfeae665e1deb77048 100644 --- a/VectoCommon/VectoCommon/Utils/Validation.cs +++ b/VectoCommon/VectoCommon/Utils/Validation.cs @@ -114,19 +114,31 @@ namespace TUGraz.VectoCommon.Utils const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy; - var prop = obj.GetProperty(m.Name, flags); - if (prop != null) { - attributes = prop.GetCustomAttributes(typeof(T)) - .Cast<T>() - .Concat(obj.GetInterfaces().SelectMany(m.GetAttributes<T>)); + + if (m.MemberType == MemberTypes.Property) { + PropertyInfo prop = m as PropertyInfo ?? obj.GetProperty(m.Name, flags); + //var prop = obj.GetProperty(m.Name, flags); + if (prop != null) + { + //if (m is PropertyInfo prop) { + attributes = prop.GetCustomAttributes(typeof(T)) + .Cast<T>() + .Concat(obj.GetInterfaces().SelectMany(m.GetAttributes<T>)); + } } - var field = obj.GetField(m.Name, flags); - if (field != null) { - attributes = - attributes.Concat( - field.GetCustomAttributes(typeof(T)).Cast<T>().Concat(obj.GetInterfaces().SelectMany(m.GetAttributes<T>))); + if (m.MemberType == MemberTypes.Field) { + FieldInfo field = m as FieldInfo ?? obj.GetField(m.Name, flags); + //var field = obj.GetField(m.Name, flags); + if (field != null) + { + //if (m is FieldInfo field) { + attributes = + attributes.Concat( + field.GetCustomAttributes(typeof(T)).Cast<T>().Concat(obj.GetInterfaces().SelectMany(m.GetAttributes<T>))); + } } + return attributes; }