简体   繁体   English

FxCop静态代码分析:将“DB”(和其他)视为“Id”

[英]FxCop Static Code Analysis: Treat “DB” (and others) like “Id”

All projects that I know - including Entity Framework (which is Microsoft itself!) - use "Db" instead of "DB". 我所知道的所有项目 - 包括Entity Framework(微软本身!) - 使用“Db”而不是“DB”。 So they treat "Db" as an abbreviation. 因此他们将“Db”视为缩写。 But FxCop treats the term as an acronym so you have to call it "DB". 但是FxCop将该术语视为首字母缩略词,因此您必须将其称为“DB”。 I have similar other terms that I like to be written like abbeviations. 我有类似的其他术语,我喜欢写作像abbeviations。 How do I force FxCop to do so? 我如何强制FxCop这样做? I want the same behavior as with "Id". 我想要与“Id”相同的行为。 Adding a custom dictionary is the first step I think, but to add "Db" to Dictionary/Acronyms/CasingExceptions is not enough. 添加自定义词典是我认为的第一步,但是将“Db”添加到Dictionary / Acronyms / CasingExceptions是不够的。 You are still able to call it "DB". 你仍然可以称之为“DB”。 "Db" is accepted but not forced. “Db”被接受但不被强制。 Somehow "Id" is really forced you are not allowed to call it "ID". 某种程度上“Id”真的被强迫你不能称它为“ID”。

I've already taken a look at 我已经看过了

"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Team Tools\\Static Analysis Tools\\FxCop\\CustomDictionary.xml" “C:\\ Program Files(x86)\\ Microsoft Visual Studio 10.0 \\ Team Tools \\ Static Analysis Tools \\ FxCop \\ CustomDictionary.xml”

to figure out how they did it. 弄清楚他们是如何做到的。 But "Id" is not part of this default dictionary maybe there is another one? 但“Id”不是这个默认字典的一部分,也许还有另一个?

Any ideas? 有任何想法吗?


Additionally I don´t understand why "DB" is not handled as an abbreviation by default it´s an abbreviation for "database" like "Id" is an abbreviation of "identifier": 另外我不明白为什么“DB”没有作为缩写处理,默认情况下它是“database”的缩写,“Id”是“identifier”的缩写:

http://msdn.microsoft.com/en-us/library/ms182256(v=VS.80).aspx http://msdn.microsoft.com/en-us/library/ms182256(v=VS.80).aspx

Maybe because of some other exceptions where it is no abbreviation but an acronym? 也许是因为其他一些例外,它不是缩写而是首字母缩略词? Lets say "Doggy Bag" ("DB")? 让我们说“Doggy Bag”(“DB”)?

The treatment of Id is hard-coded in Microsoft.FxCop.Rules.Naming.CasingWordParser.CheckAbbreviation() (at least in VS 10), and there's essentially nothing you can do to get wired into that logic. Id的处理在Microsoft.FxCop.Rules.Naming.CasingWordParser.CheckAbbreviation()硬编码(至少在VS 10中),并且基本上没有什么可以做到连接到该逻辑。

As for why DB is considered to be an acronym rather than an abbreviation, it's probably because "database" was originally "data base". 至于为什么DB被认为是首字母缩略词而不是缩写,可能是因为“数据库”最初是“数据库”。 (The separate word form still seems to be in use, although it's pretty darn rare compared to the compound form.) According to the design guidelines, we shouldn't be using "db" at all if it's an abbreviation, so I guess we should consider ourselves lucky that it's considered an acronym in the first place. (单独的单词形式似乎仍在使用中,虽然与复合形式相比,它相当罕见。)根据设计指南,如果它是缩写,我们根本不应该使用“db”,所以我想我们应该认为自己很幸运,它首先被认为是首字母缩略词。 ;) ;)

All that said, I've personally been finding the capitalization of two-letter acronyms increasingly unpleasant as time goes on. 所有这一切,我个人一直在发现随着时间的推移,两个字母缩略词的大写越来越不愉快。 I find that it looks ugly and "exceptional", and it seems to be counter-intuitive for pretty much everyone who is introduced to the design guidelines for the first time. 我发现它看起来很丑陋和“特殊”,而且对于几乎每个第一次被引入设计指南的人来说,它似乎都是违反直觉的。 I've never seen an explanation for why the design guidelines team originally thought this might be a good idea, but I do have to wonder whether most of them might not wish they could reverse the decision if they had a chance to today. 我从来没有看到为什么设计指南团队最初认为这可能是一个好主意的解释,但我不得不怀疑他们中的大多数人是否可能不希望如果他们有机会今天就可以扭转这一决定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM