What's the best way to communicate the purpose of a string parameter in a public API?

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-06-02T15:57:25Z Indexed on 2010/06/02 16:04 UTC
Read the original article Hit count: 217

Filed under:
|
|
|

According to the guidance published in New Recommendations for Using Strings in Microsoft .NET 2.0, the data in a string may exhibit one of the following types of behavior:

  1. A non-linguistic identifier, where bytes match exactly.
  2. A non-linguistic identifier, where case is irrelevant, especially a piece of data stored in most Microsoft Windows system services.
  3. Culturally-agnostic data, which still is linguistically relevant.
  4. Data that requires local linguistic customs.

Given that, I'd like to know the best way to communicate which behavior is expected of a string parameter in a public API. I wasn't able to find an answer in the Framework Design Guidelines.

Consider the following methods:

   f(string this_is_a_linguistic_string)
   g(string this_is_a_symbolic_identifier_so_use_ordinal_compares)

Is variable naming and XML documentation the best I can do? Could I use attributes in some way to mark the requirements of the string?

Now consider the following case:

   h(Dictionary<string, object> dictionary)

Note that the dictionary instance is created by the caller. How do I communicate that the callee expects the IEqualityComparer<string> object held by the dictionary to perform, for example, a case-insensitive ordinal comparison?

© Stack Overflow or respective owner

Related posts about c#

Related posts about design