Is there any way to disable the use of the "dynamic" keyword in .net 4?
I thought the Code Analysis feature of VS2010 might have a rule to fail the build if the dynamic keyword is used but I couldn't fine one.
Is there any way to disable the use of the "dynamic" keyword in .net 4?
I thought the Code Analysis feature of VS2010 might have a rule to fail the build if the dynamic keyword is used but I couldn't fine one.
It's part of the C# 4.0 language, so no not really.
You can use FXCop to look for it though and fail the build if it encounters it.
Style cop might work instead:
http://code.msdn.microsoft.com/sourceanalysis
Here is a link talking about the same issue and how style cop might be the answer. There is also a post about how to get FX cop to potentially look for the dynamic keyword, although it's not perfect.
http://social.msdn.microsoft.com/Forums/en/vstscode/thread/8ce407ba-bdf7-422b-bbcd-ca4701c3a76f
Target .net 1.0? :-)
Or do code reviews.
(Or, to be less facetious, it should be pretty easy to write a custom FxCop or CA rule to disallow use of dynamic)
Wouldn't you just kill for a C++ macro right now? :-)
The dynamic keyword is not evil, but using it could be.
It leads to code errors that you can only find during runtime. This should be avoided at all costs. Runtime errors are bad. Compile time errors are good.
You could use something like the following to set your own standards. http://joel.fjorden.se/static.php?page=CodeStyleEnforcer
Remove the reference to Microsoft.CSharp.dll
, and I think maybe all uses of dynamic
will fail to compile.
I'm not sure I understand what this irrational fear of the dynamic keyword is for. There was this type of hysteria over anonymous variables and the var keyword for .NET 3.5 except that was just idiotic since those are legitimate statically defined types.
The dynamic keyword serves a highly specialized purpose, I don't see why any person would have the desire to use it without understanding why. However stopping that from occurring could be solved with 1 team meeting explaining some of the new features of .NET 4 including the dynamic keyword. I assume you're more of a senior or the senior lead of the team; it should be quite easy to tell your team if they ever feel they NEED to use the dynamic keyword to come see you FIRST.
This was exactly the instructions I gave to my team as I find it unlikely we will ever use the dynamic keyword because we don't write COM interop activity. And past that I will defer any type of dynamic proxy use to an established library like Linfu or Castle and leave up the implementation of dynamic proxies to them to use or not use the dynamic keyword.
Can't comment, but:
Chris Marisic, the problem is uneducated RAD - victims and wannabe renegades who think that writing code in a "zomg dynamic" language is "1337 kewl".
We will see even the strategy pattern "implemented" with the dynamic keyword, because many "developers" (well, they are not really devs, but they call themselves devs...) will go "hey, dynamic saves we the work of actually defining a contract and I can still get the job done - and since I get paid for that, I don't care about the future, this is only a job".
And people like me will have to live with the consequences.