8 марта 2012 г. 12:37
I am using FxCop 1.36 and VS 2010. I am trying to write the custom code for my project coding standards. I have a rule that 'Do add the suffix 'EventHandler' to names of delegates that are used in events'. 'How can I identify the delegate that are used in events' by using FxCop code. Can anyone help me out in this issue.
8 марта 2012 г. 13:20
Do you care about delegates that are actually used for event declarations, or any delegate that might be used for an event declaration?
BTW, FxCop ships with a rule (CA1003: UseGenericEventHandlerInstances) that verifies that one is using EventHandler<TEventArgs> instead of declaring custom event handler delegates. If you are using this rule (which I would recommend), your proposed rule should become essentially useless.
9 марта 2012 г. 2:50
Thanks for your reply. Any delegate that might be used for an event declaration in my code. And I have two rules on delegates.
Rule1: Do add the suffix 'EventHandler' to names of delegates that are used in events
Rule2: Do add the suffix 'Callback' to names of delegates other than those used as event handlers
Thats why I want to identify the delegate that are used in events by using FxCop. If anybody know Please help me out.
I will ignore the rule CA1003 in FxCop.
9 марта 2012 г. 14:13
You've included two rather contradictory requests in your last message: "Any delegate that might be used for an event declaration in my code" and "identify the delegate that are used in events". Any delegate type could be used for an event handler, even if it does not follow the recommended event handler pattern (void return type and two parameters, with first of type Object, and second assignable to EventArgs). Conversely, a delegate with EventArgs argument won't necessarily be used for an event handler.
So... Do you want to pursue the "actually used for an event" approach (which would be very problematic for public delegates, where the consuming event might not be included in the FxCop analysis run targets), or would you rather use the recommended event delegate signature to detect delegate types that might be used for events?
By the way, the fact that you're concerned about these naming conventions suggests that you are seriously underconsuming the available generic delegates, particularly Action<...>, Func<...>, and EventHandler<TEventArgs>. If you use these as intended, you should be creating so few manually declared delegate types that attempting to standardize their names should seem like overkill.
- Помечено в качестве ответа Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator 19 марта 2012 г. 2:15
15 марта 2012 г. 2:19Модератор
Could you get useful information from Nicole’s reply? Have you solved this issue?
If not, please let us know the latest news about this issue.
Thank you for your understanding!
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us