Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

MetadataStringComparer Struct

Definition

Namespace:
System.Reflection.Metadata
Assembly:
System.Reflection.Metadata.dll
Package:
System.Reflection.Metadata v11.0.0-preview.5.26302.115
Source:
MetadataStringComparer.cs
Source:
MetadataStringComparer.cs
Source:
MetadataStringComparer.cs
Source:
MetadataStringComparer.cs
Source:
MetadataStringComparer.cs
Source:
MetadataStringComparer.cs
Source:
MetadataStringComparer.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Provides string comparison helpers to query strings in metadata while avoiding allocation if possible.

public value class MetadataStringComparer
public struct MetadataStringComparer
public readonly struct MetadataStringComparer
type MetadataStringComparer = struct
Public Structure MetadataStringComparer
Inheritance
MetadataStringComparer

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 reobtaining 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.

Applies to


Feedback

Was this page helpful?