MetadataStringComparer Struct
Definition
Provides string comparison helpers to query strings in metadata while avoiding allocation if possible.
public value class MetadataStringComparer
public struct MetadataStringComparer
type MetadataStringComparer = struct
Public Structure MetadataStringComparer
- Inheritance
Remarks
No allocation is performed unless both the handle argument and the value argument contain non-ASCII text.
Obtain instances using StringComparer. A default-initialized instance is useless and behaves as a null
reference.
The code is optimized so that there is no additional overhead in re-obtaining a comparer over assigning it to a local. That is to say that a construct like:
if (reader.StringComparer.Equals(typeDef.Namespace, "System") && reader.StringComparer.Equals(typeDef.Name, "Object")
{
/* found System.Object */
}
is no less efficient than:
var comparer = reader.StringComparer;
if (comparer.Equals(typeDef.Namespace, "System") && comparer.Equals(typeDef.Name, "Object")
{
/* found System.Object */
}
The choice between them is therefore one of style and not performance.