public static bool HasClrAttribute(this IParameterDeclaration parameterDeclaration, System.Type attributeType) { Contract.Requires(parameterDeclaration != null); Contract.Requires(attributeType != null); Contract.Requires(attributeType.IsAttribute()); Contract.Assert(parameterDeclaration.DeclaredElement != null); return parameterDeclaration.DeclaredElement.HasAttributeInstance( new ClrTypeName(attributeType.FullName), false); }
public static bool HasClrAttribute(this IParameter parameter, System.Type attributeType) { Contract.Requires(parameter != null); Contract.Requires(attributeType != null); Contract.Requires(attributeType.IsAttribute()); // TODO: in tests "JetBrains.Annotation.CanBeNull" could not be resolved, that's why // attributeInstance.GetClrName returns unresolved name without apropriate full name. // So, I've added a workaround and trying to compare with "PresentableName" which is "CanBeNull" in this case. return parameter .GetAttributeInstances(false) .Any(a => a.GetClrName().With(x => x.FullName) == attributeType.FullName || attributeType.Name.Contains(a.GetAttributeType().GetPresentableName(CSharpLanguage.Instance))); }