Some. Net specifications derived from fxcop are recommended from: http://msdn.microsoft.com/zh-cn/library/ms228593%28v=VS.80%29.aspx)

Source: Internet
Author: User
Tags comparable uppercase letter
Some normative suggestions from fxcop

The following code is compiled according to the. NET code specification compiled by fxcop for reference only.
I. Design)
1.
Abstract types shocould not have Constructors
Abstract classes should not declare Constructor
2.
Assemblies shocould have valid Strong names
The Assembly should have a strong name
3. Avoid
Empty Interfaces
Avoid using empty Interfaces
4. Avoid excessive parameters on
Generic types
Avoid using too many type parameters in a generic class
5. Avoid namespaces with few types

Avoid having too few types in the namespace
6. Avoid out parameters
Avoid using out parameters
7.
Collections shocould implement generic interface
Set class should implement generic interface
8.
Consider passing base types as parameters
Use the basic type as a parameter whenever possible
9. Declare
Event Handlers correctly
Correctly declare the event processor. The event processor should not have a return value.
10. Declare
Types in namespaces
Type should be defined in the namespace, rather than outside
11. Default parameters
Shocould not be used
Parameter default value should not be used (C # No parameter default value)
12. Define accessors
Attribute arguments
The accessor should be defined for the constructor parameter of the feature (feature). Its name is different from that of the constructor parameter only in the upper and lower case.
13.
Do not catch general exception types
Do not catch Common exceptions (System. Exception)
14.
Do not declare protected members in sealed types
Do not define protected members in the closed type
15.
Do not declare static members on generic types
Do not use static members in generic types
16.
Do not declare virtual members in sealed types
Do not define virtual members in the closed type
17.
Do not declare visible instance fields
Do not define visible (public/internal) instance domain changes
Quantity
18. Do not expose generic lists
Do not expose the fan table directly.
19. Do not hide
Base class methods
Do not hide (use or do not use new) Methods of the base class
20. Do not nest generic
Types in member signatures
Do not nest a generic class in the member's signature (parameter or return value)
21. Do not
Override operator equals on reference types
Do not overload the = operator in the reference type
22.
Do not pass types by reference
Do not use the reference (ref or out) Transfer Type
23. Enum
Storage shocould be Int32
Enumeration should be Int32 type
24. Enumerators shocould be
Stronugly typed
The Enumerator should be strongly typed.
25. Enums shocould have zero value
Enumeration
It should have a value of 0
26. Generic methods shold provide type parameter
The method of the generic class should be
Provide type parameters
27. ICollection implementations have stronugly typed members
Set
A strongly typed member should be used in the implementation of the combined interface.
28. Implement standard exception constructors
Custom
The four standard constructor methods of the exception class should be implemented.
29. Indexers shocould not be multidimensional
Suo
It should not be multidimensional.
30. Interface methods shocould be callable by child types
Connect
The interface method should be called by the quilt class.
31. Lists are stronugly typed
The table should be strongly typed.
32. Mark
Assemblies with assembly version
Use the assembly version to mark the Assembly
33. Mark assemblies
With CLSCompliant
Use the CLSCompliant feature to mark the Assembly
34. Mark assemblies
ComVisible
Use System. Runtime. InteropServices. ComVisibleAttribute
Feature flag assembly
35. Mark attributes with AttributeUsageAttribute
Use
AttributeUsageAttribute
36. Mark enums with FlagsAttribute
Including
The FlagsAttribute feature should be used for enumeration with combinations. On the contrary
37. Members shocould not expose
Certain concrete types
The specific type of a member (return value or parameter) should not be exposed. Use the interface whenever possible.
38. Move
Pinvokes to native methods class
Move the call to the local method class (not very understandable)
39. Nested
Types shoshould not be visible
The nested type should not be visible.
40. Override methods on
Comparable types
Methods such as equals should be rewritten for comparable types
41. Override operator equals
On overriding add and subtract
During the rewrite + and-operations, the = operator should be rewritten at the same time.
42.
Properties shocould not be write only
Attribute should not be written only
43. Provide
ObsoleteAttribute message
Outdated members should use the ObsoleteAttribute feature and provide the corresponding
Message prompt
44. Replace repetitive arguments with params array
Use
Parameter arrays replace repeated Parameters
45. Static holder types shoshould be sealed
Only types containing static members should be
Declared as closed
46. Static holder types shocould not have constructors
Only static
The member type should have a constructor Method
47. String uri overloads call system uri overloads
Use
The overload of string-type uri parameters should call the system's overload of using URI-type parameters
48. Types shocould not extend
Certain base types
The type should not be inherited from a specific class (a derived class). For example, the exception class should not
ApplicationException inherits from System. Exception
49. Types that own
Disposable fields shocould be disposable
The types that contain releasable members should be releasable (Implementation
IDisposable Interface)
50. Types that own native resources shoshould be
Disposable
The types of unmanaged resources used should be releasable (implementing the IDisposable Interface)
51. Uri parameters
Shocould not be strings
The Uri parameter should not be of the string type.
52. Uri properties
Shocould not be strings
The Uri attribute should not be of the string type.
53. Uri return values
Shocould not be strings
The returned value of the Uri type should not be of the string type.
54. Use events
Where appropriate
Use events as appropriate
55. Use generic event handler
Instances
Use a generic event processor instance
56. Use generics where appropriate
When appropriate
When using the Model
57. Use integral or string argument for indexers
The indexer should use an integer.
Number or string type parameters
58. Use properties where appropriate
Use attributes when appropriate (instead of using
Get or set)
59. Validate arguments of public methods
Public Method
Parameters should be checked at the beginning of the method (for example, whether it is null)
Ii. Globalization)
1. Avoid
Duplicate Accelerators
Avoid repeated shortcut keys (acceleration keys) in top-level controls)
2. Do not hardcode
Locale specific strings
Do not hard encode special local strings (such as special system paths ).
3. Do not
Pass literals as localized Parameters
Do not pass the text directly as a parameter that requires localization (use resource files whenever possible)
4.
Set locale for Data Types
Set region and language attributes for some data types (locale of dataset and datatable
)
5. Specify cultureinfo
Specify the cultural information (Region and language information ).
System. Globalization. The cultural information should be transmitted when the method of the cultureinfo type parameter is used.
6. Specify
Iformatprovider
Specify the format provider.
The format provider should be passed when the type parameter method is used.
7. Specify messageboxoptions
Specify the MessageBox option.
The MessageBox. Show method should be passed in system. Windows. Forms. messageboxoptions, especially when reading from right to left
Habitual Region

Iii. Interoperability)
1. Auto layout types shold
Not be comvisible
The Automatic Layout type should not be visible to com (Set
The feature of system. runtime. interopservices. comvisibleattribute is false)
2. Avoid
Int64 arguments for VB6 clients
Avoid int64 type. If a Member may be
COM clients call
3. Avoid non-public fields in comvisible value types
Dodge
Do not include non-public instance domains in a value type marked with the comvisible feature

4. Avoid overloads in
Comvisible Interfaces
Avoid declaring overloading in an interface with the comvisible feature
5. Avoid
Static members in comvisible types
Avoid marking a type with the comvisible feature
6.
Call getlasterror immediately after pinvoke
Use pinvoke immediately
Getlasterror read error message
7. com registration methods shoshould be matched
Com
Registration Method (marked with the feature system. runtime. interopservices. comregisterfunctionattribute)
Method) should be paired (with a tag
The method of system. runtime. interopservices. comunregisterfunctionattribute matches with it)
8.
Com registration methods shocould not be visible
The com registration method should be invisible.
9.
Com visible type base types shoshould be comvisible
Indicates the type with the comvisible feature
The base class of should also inherit from the class marked with the comvisible feature
10. com visible types shocould be creatable
Mark
Note that the types with the comvisible feature should be constructed using the default constructor.
11. Declare PInvokes correctly
Confirm
Yi PInvokes
12. Do not use AutoDual ClassInterfaceType
Do not set
Set System. Runtime. InteropServices. ClassInterfaceAttribute
System. Runtime. InteropServices. ClassInterfaceType. AutoDual
13. Mark
Boolean pinvoke arguments with specified alas
Boolean pinvoke parameter should be used
System. Runtime. InteropServices. MarshalAsAttribute feature mark
14. Mark
ComSource interfaces as IDispatch
Set
The System. Runtime. InteropServices. ComSourceInterfacesAttribute feature is marked
System. Runtime. InteropServices. ComInterfaceType. InterfaceIsIDispatch.
15.
PInvoke entry points shold exist
Pinvoke should have an entry point
16. PInvokes
Shocould not be visible
Pinvoke should be visible
Iv. Naming)
1. Avoid
Language specific type names in parameters
Avoid using types related to specific languages in parameters (Use
Uint16 instead of Ushort)
2. Avoid type names in parameters
Avoid using types in externally visible Parameters
Name
3. Compound words shocould be cased correctly
Compound Words should use correct case (do not set
Do not write the ToolBar as a Toolbar and FileName as Filename)
4. Do
Not name enum values 'reserved'
Do not use reserved words in enumeration values
5. Do not prefix
Enum values with type name
Do not use a type prefix in the enumerated values (for example, do not use a Digital prefix)
6.
Events shoshould not have before or after prefix
The event name should not contain before and after
Prefix (use the suffix of ing and ed whenever possible)
7. Flags enums shocould have plural names
Marked
The enumeration of the System. FlagsAttribute feature should be in the plural form.
8. Identifiers shoshould be cased
Correctly
The identifier (namespace, class name, attribute name, Interface Name, method name, and so on) should use the correct case (usually starts with an uppercase letter, and each word in the future is capitalized)
9.
Identifiers shoshould be spelled correctly
The identifier should be correctly divided into different words.
10.
Identifiers shoshould differ by more than case
The identifier should not only be case-insensitive (because some languages are not
Case Sensitive)
11. Identifiers shocould have correct prefix
The identifier should use the correct prefix
Should start with the letter I)
12. Identifiers shocould have correct suffix
The identifier should be correct
Suffix
System. Attribute/attribute
System. eventargs/eventargs
System. Exception/exception

System. Collections. icollection/Collection
System. Collections. idictionary/Dictionary

System. Collections. ienumerable/Collection
System. Collections. Queue/Collection
Or Queue
System. Collections. Stack/Collection or Stack
System. Collections. Generic. ICollection/Collection

System. Collections. Generic. IDictionary/Dictionary
System. Data. DataSet/DataSet

System. Data. DataTable/Collection or DataTable
System. IO. Stream/Stream

System. Security. IPermission/Permission
System. Security. Policy. IMembershipCondition/Condition

An event-handlerdelegate./EventHandler
13. Identifiers shocould
Not contain underscores
Underlines should not be used for the identifier
14. Identifiers shocould not
Have incorrect prefix
The identifier should not use an incorrect prefix (for example, a letter should not be used as the prefix)
15.
Identifiers shoshould not have incorrect suffix
The identifier should not use an incorrect suffix (not in an incorrect location
Use the suffix names mentioned in 12 and the suffix names such as Delegate, Enum, Flags for an enumeration, and Impl)
16.
Identifiers shocould not match keywords
The identifier should not conflict with the system keyword.
17. Long
Acronyms shoshould be pascal-cased
For acronyms with a length greater than or equal to 3, use pascal's naming rules, that is, uppercase letters.
18.
Only FlagsAttribute enums shoshould have plural names
Only marked
The enumerated names of the System. FlagsAttribute feature must use the plural value. Otherwise, the singular value should be used.
19. Parameter names
Shocould match base declaration
The Parameter Name of the derived item should be consistent with the base item (the method of rewriting or implementation of the derived class should have the same parameters as the base item
Number of instances)
20. Parameter names shocould not match member names
The parameter names of methods should not be the same
Or the interface has the same member name.
21. Property names shocould not match get methods
Attribute name should not
The second half of the name of the method starting with Get is the same.
22. Resource string compound words shocould be
Cased correctly
The resource string containing the words should use the correct case (the first letter of each word is capitalized)
23. Resource
Strings shoshould be spelled correctly
The resource string should be correctly spelled
24. Short
Acronyms shocould be uppercase
Short acronyms should all be capitalized (such as DB and CR)
25. Type
Names shocould not match namespaces
The type name should not be the same as the namespace name

26. Use
Preferred terms
Some projects or names are preferred.
ComPlus/EnterpriseServices

Cancelled/Canceled
Indices/Indexes
LogIn/LogOn
LogOut/LogOff

SignOn/SignIn
SignOff/SignOut
Writeable/Writable
V,
Performance (Performance rules)
1. Avoid cballs that require unboxing
Avoid calling a method.
Returns the object type, and you need a value type (you need to unpack the returned value)
2. Avoid costly cballs where
Possible
Avoid Expensive calls as much as possible
3. Avoid excessive locals
Avoid using too many local variables
(More than 64, some may be generated by the compiler)
4. Avoid uncalled private code
Avoid declaring never called in the Assembly
Private and internal, except the following:
Clear interface member
Static Constructor

Static Main method (excluding parameters or containing only parameters of a string array)
Serialization Constructor

System. Runtime. InteropServices. ComRegisterFunctionAttribute or
System. Runtime. InteropServices. ComUnregisterFunctionAttribute. Feature

Override Method
5. Avoid uninstantiated internal classes
Avoid declaring internal classes that will not be instantiated.
Except
Value Type
Abstract type
Enumeration
Delegate
Array type generated by the compiler
Internal class containing only static members
6.
Avoid unnecessary string creation
Avoid creating unnecessary string instances.
ToUpper created string '), including the following situations

ToLower and ToUpper are called multiple times for the same string instance (we recommend that you assign the return value to a local variable and then use this local variable)

Use equals, '= ',! = Compare 'string' created through ToLower and ToUpper (recommended: string. Compare)

To a System. Collections. Specialized. HybridDictionary type member, pass 'through ToLower and
ToUpper-created string' (recommended: HybridDictionary has a constructor overload that indicates whether to ignore case-insensitive parameters. Use this overload and pass
True)
7. Avoid unsealed attributes
Avoid declaring unclosed attributes (attributes) (Suggestion: Sound
Is sealed/NotInheritable-vb.net or abstract)
8. Avoid unused parameters
Dodge
Do not include unused parameters in the method declaration, except in the following cases
Proxy Reference Method
Method used as an event handler
Abstract)
Virtual)
Override)
External method (extern)
9. Dispose Methods
Shocould call suppressfinalize
The dispose method should call suppressfinalize to request the system not to call
Its Finalize method
10. Do not call properties that clone values in Loops
No
To use 'Return the attributes of a clone object' in a loop (each return 'reference a different 'object will lead to the creation of a large number of identical objects)
11. Do not cast
Unnecessarily
Do not perform unnecessary type conversion (especially for trial conversions. We recommend that you use the is operator to determine whether the conversion is successful before conversion)
12.
Do not concatenate strings inside Loops
Do not concatenate strings in a loop (we recommend that you use
Stringbuilder replaces string)
13. Do not ignore Method Results
Do not ignore the returned Method
Value (the new string is usually returned when the string method is called)
14. Do not initialize unnecessarily
No
Perform unnecessary initialization (for example, initializing a class member as its default value)
15. initialize reference type static
Fields inline
Directly initialize or call static method initialization when declaring static members (do not use static constructor to initialize static members. Static constructor will affect
Performance), except in the following situations:
Initialization has a high impact on the global status, and the type does not need to be initialized before use.

If you do not need to access this type of static members, the global status can be accessed.
16. Override equals and operator
Equals on value types
For public value types, rewrite the equals method and the '=' operator (if you want the user to compare or sort instances,
Or as the key of the hash table)
17. Prefer jagged arrays over multidimenys
Use a sawtooth Array
Replace multi-dimensional array (when the length of each element in the array may be inconsistent)
Note: The common language specification (CLS) does not support sawtooth arrays.
18. Properties
Shocould not return arrays
Attribute of the Public type should not return an array (the attribute of the array type cannot be write-protected, even if it is read-only, unless each return
Different copies, but this will confuse the caller. Suggestion: change to method)
19. Remove empty finalizers
Remove an empty Terminator
20.
Remove unused locals
Remove unused local variables
21. Test for empty strings using
String length
Use the length attribute to test whether the String is null (reason: Do not use = ", = String... Empty,
Equals ("") and other methods, the efficiency of using the Length attribute is the highest; null = empty does not throw an exception; In DotNetFrameWork2, you can
Use the IsNullOrEmpty method to determine whether the string is null or empty)
22. Use literals where
Appropriate
Use const instead of static readonly when appropriate (const is assigned during compilation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.