Skip to content

[C#] Inconsistent String Comparisons in Schema Field Retrieval Methods #44650

@vthemelis

Description

@vthemelis

In the Schema class, there are three methods used to retrieve individual fields:

public class Schema
{
    // ...

    public Field GetFieldByName(string name) => FieldsLookup[name].FirstOrDefault();

    public int GetFieldIndex(string name, StringComparer comparer)
    {
        IEqualityComparer<string> equalityComparer = (IEqualityComparer<string>)comparer;
        return GetFieldIndex(name, equalityComparer);
    }

    public int GetFieldIndex(string name, IEqualityComparer<string> comparer = default)
    {
        // Implementation using the specified comparer
    }
}

The first method (GetFieldByName) use the default string comparer, while the latter two (GetFieldIndex overloads) are using a culture aware comparator by default (StringComparer.CurrentCulture). This inconsistency can be confusing, as it is unclear when custom comparers are utilized.

Component(s)

C#

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions