static bool TrySplitTagContent(string tagContent, out string propertyNameAndDestructuring, out string format, out string alignment, out MessageTemplateDiagnostic diagnostic) { var formatDelim = tagContent.IndexOf(':'); var alignmentDelim = tagContent.IndexOf(','); if (formatDelim == -1 && alignmentDelim == -1) { propertyNameAndDestructuring = tagContent; format = null; alignment = null; diagnostic = null; } else { if (alignmentDelim == -1 || (formatDelim != -1 && alignmentDelim > formatDelim)) { propertyNameAndDestructuring = tagContent.Substring(0, formatDelim); format = formatDelim == tagContent.Length - 1 ? null : tagContent.Substring(formatDelim + 1); alignment = null; diagnostic = null; } else { propertyNameAndDestructuring = tagContent.Substring(0, alignmentDelim); if (formatDelim == -1) { if (alignmentDelim == tagContent.Length - 1) { alignment = format = null; diagnostic = new MessageTemplateDiagnostic(alignmentDelim, 1, "Found alignment specifier without alignment"); return(false); } format = null; alignment = tagContent.Substring(alignmentDelim + 1); } else { if (alignmentDelim == formatDelim - 1) { alignment = format = null; diagnostic = new MessageTemplateDiagnostic(alignmentDelim, 1, "Found alignment specifier without alignment"); return(false); } alignment = tagContent.Substring(alignmentDelim + 1, formatDelim - alignmentDelim - 1); format = formatDelim == tagContent.Length - 1 ? null : tagContent.Substring(formatDelim + 1); } } } diagnostic = null; return(true); }
private static void ReportDiagnostic(ref SyntaxNodeAnalysisContext context, ref TextSpan literalSpan, string stringText, bool exactPositions, DiagnosticDescriptor rule, MessageTemplateDiagnostic diagnostic) { TextSpan textSpan; if (diagnostic.MustBeRemapped) { if (!exactPositions) { textSpan = literalSpan; } else { int remappedStart = GetPositionInLiteral(stringText, diagnostic.StartIndex); int remappedEnd = GetPositionInLiteral(stringText, diagnostic.StartIndex + diagnostic.Length); textSpan = new TextSpan(literalSpan.Start + remappedStart, remappedEnd - remappedStart); } } else { textSpan = new TextSpan(diagnostic.StartIndex, diagnostic.Length); } var sourceLocation = Location.Create(context.Node.SyntaxTree, textSpan); context.ReportDiagnostic(Diagnostic.Create(rule, sourceLocation, diagnostic.Diagnostic)); }