I am trying to find all properties containing an object that implements an interface, and execute a method on an object. This is the code that I still have:
foreach (var propertyInfo in this.GetType().GetProperties()
.Where(xx => xx.GetCustomAttributes(typeof(SearchMeAttribute), false).Any()))
{
if (propertyInfo.PropertyType.GetInterfaces().Any(xx => xx == typeof(IAmSearchable)))
{
return ((IAmSearchable)propertyInfo).SearchMeLikeYouKnowIAmGuilty(term);
}
}
Sorry, I get an error message:
Cannot overlay object of type "System.Reflection.RuntimePropertyInfo" with type "ConfigurationServices.ViewModels.IAmSearchable".
How can I get the actual object, not RuntimePropertyInfo?
source
share