KnownType attribute and unused method

Would it be possible to add to Resharpers code analysis so that it understands the known type attribute.

Firstly so that you can autocomplete the function name in the string parameter and secondly so that it doesn't mark the method as unused.

3 comments
Comment actions Permalink

Could you expand on this a bit? Do you mean the KnownTypeAttribute from WCF? Coud you describe the scenario in a bit more depth, please?

Thanks
Matt

0
Comment actions Permalink

Yes the WCF KnownTypesAttribute, for example in the code below the KnownTypes function shows as never used

[System.Runtime.Serialization.KnownType("KnownTypes")]
public class MyClass {
     private static IEnumerable<Type> KnownTypes() {
         yield return typeof(MyClass2);
     }

}

0
Comment actions Permalink

Nothing exists in the product to do this at the moment. You can add a feature request to our issue tracking tool here: http://youtrack.jetbrains.com or you could implement a plugin that provides this functionality. The NUnit support in ReShaprer provides a good example of how to do this - essentially, you create a reference between the string element in the attribute and the method/property in the class. ReSharper handles everything from there - if the reference is unresolved, it's displayed as an error, if it's there, you can control click navigate and it will show up in find usages.

Adding code completion is also fairly straight forward - you add another class that overrides 2 methods, one to check for availability, and one to look for a list of likely methods/properties in the class.

TestCaseSourceReferenceProviderFactory is a good place to start, and the code completion is implemented in TestCaseSourceReferenceSuggestionRule. Take a look at those classes, and the classes they reference/create in dotPeek, and you should hopefully be able to follow it from there.

Thanks
Matt

0

Please sign in to leave a comment.