07-20-2023, 03:40 PM
According to the guidance published in [New Recommendations for Using Strings in Microsoft .NET 2.0][1], the data in a string may exhibit one of the following types of behavior:
1. A non-linguistic identifier, where bytes match exactly.
1. A non-linguistic identifier, where case is irrelevant, especially a piece of data stored in most Microsoft Windows system services.
1. Culturally-agnostic data, which still is linguistically relevant.
1. 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][2].
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&lt;string&gt; object held by the dictionary to perform, for example, a case-insensitive ordinal comparison?
[1]:
1. A non-linguistic identifier, where bytes match exactly.
1. A non-linguistic identifier, where case is irrelevant, especially a piece of data stored in most Microsoft Windows system services.
1. Culturally-agnostic data, which still is linguistically relevant.
1. 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][2].
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&lt;string&gt; object held by the dictionary to perform, for example, a case-insensitive ordinal comparison?
[1]:
[To see links please register here]
[2]:[To see links please register here]