-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Description
Here is the TryParse method's body:
public static bool TryParse(string text, out MetricSpec spec)
{
int slashIdx = text.IndexOf(MeterInstrumentSeparator);
if (slashIdx == -1)
{
spec = new MetricSpec(text.Trim(), null);
return true;
}
else
{
string meterName = text.Substring(0, slashIdx).Trim();
string? instrumentName = text.Substring(slashIdx + 1).Trim();
spec = new MetricSpec(meterName, instrumentName);
return true;
}
}It always returns true.
The ParseSpecs method uses TryParse as follows:
if (!MetricSpec.TryParse(specString, out MetricSpec spec))
{
Log.Message($"Failed to parse metric spec: {specString}");
}
else
{
....
}As a result the then branch of the if statement is unreachable.
Is the code designed for future changes in the TryParse method or is it an error here?
Links to the sources: