Permalink
Browse files

Fixed determination of attribute base types when using ReSharper's Me…

…tadata API
  • Loading branch information...
1 parent 3208002 commit bc8f95b7c44b721d868137a685bf74984d56a0ba @agross agross committed Jan 25, 2013
Showing with 24 additions and 6 deletions.
  1. +24 −6 Source/Machine.Specifications.ReSharperRunner.6.1/MetadataExtensions.cs
@@ -80,13 +80,14 @@ public static string GetSubjectString(this IMetadataEntity type)
private static IList<IMetadataCustomAttribute> GetSubjectAttributes(IMetadataEntity type)
{
- return (from customAttribute in type.CustomAttributes
- where customAttribute.AndAllBaseTypes().Any(i => i.FullyQualifiedName == typeof(SubjectAttribute).FullName)
- select customAttribute).ToList();
+ return type.CustomAttributes
+ .Where(attribute => attribute.AndAllBaseTypes()
+ .Any(i => i.FullyQualifiedName == typeof(SubjectAttribute).FullName))
+ .ToList();
}
public static ICollection<string> GetTags(this IMetadataEntity type)
- {
+ {
return type.AndAllBaseTypes()
.SelectMany(x => x.GetCustomAttributes(typeof(TagsAttribute).FullName))
.Select(x => x.ConstructorArguments)
@@ -98,10 +99,27 @@ public static ICollection<string> GetTags(this IMetadataEntity type)
static IEnumerable<IMetadataTypeInfo> AndAllBaseTypes(this IMetadataEntity type)
{
+ Func<IMetadataEntity, IMetadataTypeInfo> getTypeFromAttributeConstructor = entity =>
+ {
+ var attr = type as IMetadataCustomAttribute;
+ if (attr == null)
+ {
+ return null;
+ }
+
+ return attr.UsedConstructor.DeclaringType;
+ };
+
var typeInfo = type as IMetadataTypeInfo;
if (typeInfo == null)
{
- yield break;
+ // type might be an attribute - which cannot be cast as IMetadataTypeInfo.
+ typeInfo = getTypeFromAttributeConstructor(type);
+ if (typeInfo == null)
+ {
+ // No idea how the get the type of the IMetadataEntity.
+ yield break;
+ }
}
yield return typeInfo;
@@ -199,4 +217,4 @@ static string FullyQualifiedName(this IMetadataClassType classType, bool appendA
return fullyQualifiedName.ToString();
}
}
-}
+}

0 comments on commit bc8f95b

Please sign in to comment.