private static Type GetAttributeDeclaringType(Type type, Attribute attribute)
{
while (true)
{
var attributes = type.GetCustomAttributes(attribute.GetType(), false);
foreach (Attribute a in attributes)
{
if (a.Equals(attribute))
{
return type;
}
}
type = type.BaseType;
if (type == null)
{
break;
}
}
return null;
}