private Dictionary<string, string> ParseAdditionalFile(AdditionalText additionalFile) { Dictionary<string, string> parsedPinvokes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); if (additionalFile == null) return parsedPinvokes; SourceText fileContents = additionalFile.GetText(); foreach (TextLine line in fileContents.Lines) { string lineStr = line.ToString(); if (!string.IsNullOrWhiteSpace(lineStr) && !lineStr.StartsWith("<!--")) { string[] splitCount = lineStr.Split('!'); if (splitCount.Length == 2 || splitCount.Length == 3) { parsedPinvokes[splitCount[1]] = splitCount[0]; if (splitCount.Length == 3) { _isNotSupportedOnWin7.Add(splitCount[1]); } } } } return parsedPinvokes; }
/// <summary> /// This code works around dotnet/roslyn#6596 by using reflection APIs to bypass the problematic method while /// reading the content of an <see cref="AdditionalText"/> file. If the reflection approach fails, the code /// falls back to the previous behavior. /// </summary> /// <param name="additionalText">The additional text to read.</param> /// <param name="cancellationToken">The cancellation token that the operation will observe.</param> /// <returns>The content of the additional text file.</returns> private static SourceText GetText(AdditionalText additionalText, CancellationToken cancellationToken) { if (AvoidAdditionalTextGetText) { object document = GetField(additionalText, "_document"); if (document != null) { object textSource = GetField(document, "textSource"); if (textSource != null) { object textAndVersion = CallMethod(textSource, "GetValue", new[] { typeof(CancellationToken) }, cancellationToken); if (textAndVersion != null) { SourceText text = GetProperty(textAndVersion, "Text") as SourceText; if (text != null) { return text; } } } } } return additionalText.GetText(cancellationToken); }