C # - disable dynamic keyword

Is there a way to disable the use of the "dynamic" keyword in .net 4?

I thought that the VS2010 code analysis function might have a rule so that the assembly fails if the dynamic keyword is used, but I could not distinguish it.

+7
c # visual-studio-2010 late-binding
source share
5 answers

This is part of C # 4.0, so no.

You can use FXCop to look for it, although the build fails if it encounters it.

Instead, a script might work:

http://code.msdn.microsoft.com/sourceanalysis

Here is a link talking about the same issue and how it might be a style answer. There is also a message on how to get FX cop to potentially search for a dynamic keyword, although it is not perfect.

http://social.msdn.microsoft.com/Forums/en/vstscode/thread/8ce407ba-bdf7-422b-bbcd-ca4701c3a76f

+5
source share

Target.net 1.0 ?:-)

Or view the code.

(Or, to be less fun, it should be fairly easy to write your own FxCop or CA rule to prohibit the use of dynamic)

Could you just kill the C ++ macro right now ?:-)

+2
source share

A dynamic keyword is not evil, but its use may be.

This leads to code errors that can only be found at runtime. This should be avoided at all costs. Runtime errors are bad. Compile-time errors are good.

You can use something like the following to set your own standards. http://joel.fjorden.se/static.php?page=CodeStyleEnforcer

+2
source share

Remove the link to Microsoft.CSharp.dll , and I think it is possible that all uses of dynamic will not compile.

+2
source share

I'm not sure I understand what this irrational fear of a dynamic keyword is. It was hysteria over anonymous variables and the var keyword for .NET 3.5, except that it was just idiotic, since these are legitimate statically defined types.

A dynamic keyword serves a highly specialized purpose; I don’t understand why any person would have a desire to use it without understanding why. However, stopping this from solving the problem can be solved with the help of 1 command explaining some of the new features of .NET 4, including the dynamic keyword. I believe you are more than a senior or senior team leader; it should be pretty easy for you to tell your team if they ever felt that they NEEDED to use a dynamic keyword to meet you FIRST.

These were exactly the instructions that I gave my team, since it seems unlikely that we will ever use a dynamic keyword, because we are not writing COM interaction activity. And in the past, I put off using any type of dynamic proxy to an installed library, such as Linfu or Castle, and refuse to implement dynamic proxies to use or not use a dynamic keyword.

+1
source share

All Articles