コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: PinvokeAnalyzer.cs プロジェクト: dsgouda/buildtools
        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;
        }
コード例 #3
0
ファイル: GeneratorDriver.cs プロジェクト: taori/roslyn
        public GeneratorDriver ReplaceAdditionalText(AdditionalText oldText, AdditionalText newText)
        {
            if (oldText is null)
            {
                throw new ArgumentNullException(nameof(oldText));
            }
            if (newText is null)
            {
                throw new ArgumentNullException(nameof(newText));
            }

            var newState = _state.With(additionalTexts: _state.AdditionalTexts.Replace(oldText, newText));

            return(FromState(newState));
        }
コード例 #4
0
 public override AnalyzerConfigOptions GetOptions(AdditionalText textFile)
 {
     // TODO: correctly find the file path, since it looks like we give this the document's .Name under the covers if we don't have one
     return(new WorkspaceAnalyzerConfigOptions(_projectState._lazyAnalyzerConfigSet.GetValue(CancellationToken.None).GetOptionsForSourcePath(textFile.Path)));
 }
コード例 #5
0
        private static bool TryGetApiText(ImmutableArray<AdditionalText> additionalTexts, CancellationToken cancellationToken, out AdditionalText shippedText, out AdditionalText unshippedText)
        {
            shippedText = null;
            unshippedText = null;

            var comparer = StringComparer.Ordinal;
            foreach (var text in additionalTexts)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var fileName = Path.GetFileName(text.Path);
                if (comparer.Equals(fileName, ShippedFileName))
                {
                    shippedText = text;
                    continue;
                }

                if (comparer.Equals(fileName, UnshippedFileName))
                {
                    unshippedText = text;
                    continue;
                }
            }

            return shippedText != null && unshippedText != null;
        }
コード例 #6
0
 public AdditionalFileAddedEdit(AdditionalText addedText)
 {
     AddedText = addedText;
 }