Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit fdb933b4 authored by Harald Martini's avatar Harald Martini Committed by Markus Quaritsch
Browse files

optimized usage of Reflection in ValidationHelper

(cherry picked from commit 2d9961a8)
parent 3a898a09
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment