Labels

Thursday, August 23, 2007

By FxCop

Avoid ‘out’ Parameters: By FxCop

· Using out parameters might indicate a design flaw.

· Although there are legitimate times to use out parameters, their use frequently indicates a design that does not conform to the design guidelines for managed code.

How declaring methods as ‘Static’ can increase performance? By FxCop

  • Methods which do not access instance data or call instance methods can be marked as static (Shared in VB).
  • After doing so, the compiler will emit non-virtual call sites to these members which will prevent a check at runtime for each call that insures the current object pointer is non-null.
  • This can result in a measurable performance gain for performance-sensitive code.
  • In some cases, the failure to access the current object instance represents a correctness issue.

Why Default Constructor is necessary for classes/types with only static members?

  • Instances of types that define only static members do not need to be created.
  • Many compilers will automatically add a public default constructor if no constructor is specified.
  • To prevent this, adding an empty private constructor may be required."

Static holder types should be ‘sealed’: By FxCop

  • Static holder types do not provide functionality that derived instances can extend. Inheriting from such a type indicates a flawed design.

Misc:

  • Properties that return collections should be read-only so that users cannot entirely replace the backing store.
  • Users can still modify the contents of the collection by calling relevant methods on the collection.

Exception Handling using IDisposable Interface and Dispose Method().

  • Instead of implementing only Dispose() we should implement hybrid approach.
  • Instead we should call Dispose(true), then calls GC.SuppressFinalize().

Thanks & Regards,

Arun Manglick || Tech Lead

No comments:

Post a Comment