AttributeHelper
Provides a platform-independent methods for getting attributes
for use by AttributeConstraint and AttributeExistsConstraint.
using System;
using System.Reflection;
namespace NUnit.Compatibility
{
public static class AttributeHelper
{
public static Attribute[] GetCustomAttributes(object actual, Type attributeType, bool inherit)
{
MemberInfo memberInfo = actual as MemberInfo;
if ((object)memberInfo != null)
return (Attribute[])CustomAttributeExtensions.GetCustomAttributes(memberInfo, attributeType, inherit);
ParameterInfo parameterInfo = actual as ParameterInfo;
if (parameterInfo != null)
return (Attribute[])CustomAttributeExtensions.GetCustomAttributes(parameterInfo, attributeType, inherit);
Assembly assembly = actual as Assembly;
if ((object)assembly != null)
return (Attribute[])AssemblyExtensions.GetCustomAttributes(assembly, attributeType, inherit);
throw new ArgumentException($"""{actual}""", "actual");
}
}
}