public void CheckCodeAnalysisSettingsSerialization(bool recursiveAnalysisEnabled, bool isvSpecificAnalyzersEnabled, bool staticAnalysisEnabled,
                                                           bool suppressionMechanismEnabled, bool px1007DocumentationDiagnosticEnabled)
        {
            var expectedSettings = new CodeAnalysisSettings(recursiveAnalysisEnabled, isvSpecificAnalyzersEnabled,
                                                            staticAnalysisEnabled, suppressionMechanismEnabled,
                                                            px1007DocumentationDiagnosticEnabled);

            using var stream = new MemoryStream(capacity: sizeof(bool) * 5 + 20);
            using var writer = new CodeAnalysisSettingsBinaryWriter(stream);

            writer.WriteCodeAnalysisSettings(expectedSettings);

            stream.Position = 0;

            using var reader = new CodeAnalysisSettingsBinaryReader(stream);
            var deserializedSettings = reader.ReadCodeAnalysisSettings();

            Assert.Equal(deserializedSettings, expectedSettings);
        }
Example #2
0
        public static CodeAnalysisSettings GetCodeAnalysisSettings()
        {
            if (SharedVsSettings.IsInsideVsProcess)
            {
                return(GlobalCodeAnalysisSettings.Instance);
            }

            if (!_isSharedMemoryOpened)
            {
                lock (_lock)
                {
                    if (!_isSharedMemoryOpened)
                    {
                        _memoryMappedFile     = OpenExistingMemoryMappedFile();
                        _isSharedMemoryOpened = _memoryMappedFile != null;
                    }
                }
            }

            if (_memoryMappedFile == null)
            {
                return(GlobalCodeAnalysisSettings.Instance);
            }

            try
            {
                using MemoryMappedViewStream stream = _memoryMappedFile.CreateViewStream();
                using var reader = new CodeAnalysisSettingsBinaryReader(stream);
                CodeAnalysisSettings codeAnalysisSettings = reader.ReadCodeAnalysisSettings();

                return(codeAnalysisSettings);
            }
            catch (Exception)
            {
                return(GlobalCodeAnalysisSettings.Instance);
            }
        }