Practical DiskDiff in C#: Guidelines for Library Authors

The following guidelines are useful to programmers who are writing libraries that will be used by others.

1. CLS Compliance

When writing software that will be consumed by other developers, it makes sense to comply with the CLS. This specification details what features a language should support to be a .NET-compliant language; you can find it in the “What Is the Common Language Specification” section of the .NET SDK documentation.

The C# compiler will check code for compliance if the ClsCompliant assembly attribute is placed in one of the source files.

To be CLS compliant, you have the following restrictions:

  • Unsigned types can’t be exposed as part of the public interface of a class. You can use them freely in the private part of a class.
  • Unsafe (for example, pointer) types can’t be exposed in the public interface of the class. As with unsigned types, you can use them in the private parts of the class.
  • Identifiers (such as class names or member names) can’t differ only in case.

For example, compiling the following will produce an error:

// error using System;

[CLSCompliant(true)]

class Test {

public uint Process() {return(o);}

}

2. Class Naming

To help prevent collisions between namespaces and classes provided by different companies, you should name namespaces using the CompanyName.TechnologyName convention. For example, the lull name of a class to control an X-ray laser would be something like this:

AppliedEnergy.XRayLaser.Controller

Source: Gunnerson Eric, Wienholt Nick (2005), A Programmer’s Introduction to C# 2.0, Apress; 3rd edition.

Leave a Reply

Your email address will not be published. Required fields are marked *