Is there a property equivlant for InvokerParameterNameAttribute?

The annotation attribute InvokerParameterNameAttribute gives us the ability to force the value being passed in to be one of the parameters passed in to the calling function, but how do we do the equivlant for properties so that when you type in a method it give you intellisense and validation that the string you passed in is one of the properties in the containing class.

NotifyPropertyChangedInvocatorAttribute gives us this functionalality for INPC but I want to use this for other methods then OnNotifiyPropertyChanged.

If you see the attached image, I want to give OnErrorsChanged the same intelisense OnPropertyChanged got because it had NotifyPropertyChangedInvocatorAttribute



Attachment(s):
Capture.PNG
1 comment
Comment actions Permalink

There isn't an annotation attribute that will verify that a parameter is a member of the current type. This could be rather useful, and I've added a feature request here - RSRP-440611. One of the complications here is knowing what members are applicable for the use case - public/private, static, method/properties, signature, etc.

This functionality is possible with an extension to ReSharper. You can write a reference provider that will create a reference on a string literal that resolves to a member on the current type. This gives you code completion, find usages, renaming and will highlight in red if it can't resolve correctly. And since you know your use case, you can make sure it works correctly, even looking for a Type argument so that members can live on another type. E.g. here's the reference provider for the xunit test provider plugin, that will add a reference to the [MemberData] attribute argument to provide a reference to a static property for test data.

0

Please sign in to leave a comment.