提交 e0d45543 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #15046 from CyrusNajmabadi/useOutVar

Use out-var in a few more cases.
......@@ -39,8 +39,7 @@ protected override Assembly LoadImpl(string fullPath)
private string GetAssemblyPath(string fullPath)
{
string assemblyPath;
if (_map.TryGetValue(fullPath, out assemblyPath))
if (_map.TryGetValue(fullPath, out var assemblyPath))
{
return assemblyPath;
}
......
......@@ -67,12 +67,10 @@ public static unsafe byte[] ApplyPatch(byte[] sourceBytes, byte[] patchBytes)
{
DeltaInput ds = new DeltaInput(pSourceBuf, sourceBytes.Length, true);
DeltaInput dp = new DeltaInput(pPatchBuf, patchBytes.Length, true);
DeltaOutput output;
if (!ApplyDeltaB(DeltaApplyFlag.None,
ds,
dp,
out output))
out var output))
{
throw new Win32Exception();
}
......
......@@ -410,9 +410,7 @@ private async Task<TimeSpan> ProcessPatchXElementAsync(XElement patchElement, by
private async Task<TimeSpan?> TryProcessPatchXElementAsync(XElement patchElement, byte[] databaseBytes)
{
bool upToDate, tooOld;
byte[] patchBytes;
ParsePatchElement(patchElement, out upToDate, out tooOld, out patchBytes);
ParsePatchElement(patchElement, out var upToDate, out var tooOld, out var patchBytes);
if (upToDate)
{
......
......@@ -74,8 +74,7 @@ public SymbolSearchUpdateEngine(ISymbolSearchLogService logService)
public Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity)
{
IAddReferenceDatabaseWrapper databaseWrapper;
if (!_sourceToDatabase.TryGetValue(source, out databaseWrapper))
if (!_sourceToDatabase.TryGetValue(source, out var databaseWrapper))
{
// Don't have a database to search.
return SpecializedTasks.EmptyImmutableArray<PackageWithTypeResult>();
......@@ -112,8 +111,7 @@ public SymbolSearchUpdateEngine(ISymbolSearchLogService logService)
public Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string assemblyName)
{
IAddReferenceDatabaseWrapper databaseWrapper;
if (!_sourceToDatabase.TryGetValue(source, out databaseWrapper))
if (!_sourceToDatabase.TryGetValue(source, out var databaseWrapper))
{
// Don't have a database to search.
return SpecializedTasks.EmptyImmutableArray<PackageWithAssemblyResult>();
......@@ -124,12 +122,8 @@ public SymbolSearchUpdateEngine(ISymbolSearchLogService logService)
var database = databaseWrapper.Database;
var index = database.Index;
var stringStore = database.StringStore;
Range range;
int[] matches;
int startIndex, count;
if (stringStore.TryFindString(assemblyName, out range) &&
index.TryGetMatchesInRange(range, out matches, out startIndex, out count))
if (stringStore.TryFindString(assemblyName, out var range) &&
index.TryGetMatchesInRange(range, out var matches, out var startIndex, out var count))
{
for (var i = startIndex; i < (startIndex + count); i++)
{
......@@ -152,8 +146,7 @@ public SymbolSearchUpdateEngine(ISymbolSearchLogService logService)
string name, int arity)
{
// Our reference assembly data is stored in the nuget.org DB.
IAddReferenceDatabaseWrapper databaseWrapper;
if (!_sourceToDatabase.TryGetValue(NugetOrgSource, out databaseWrapper))
if (!_sourceToDatabase.TryGetValue(NugetOrgSource, out var databaseWrapper))
{
// Don't have a database to search.
return SpecializedTasks.EmptyImmutableArray<ReferenceAssemblyWithTypeResult>();
......@@ -221,10 +214,8 @@ private PackageWithTypeResult CreateResult(AddReferenceDatabase database, Symbol
private int GetRank(Symbol symbol)
{
Symbol rankingSymbol;
int rank;
if (!TryGetRankingSymbol(symbol, out rankingSymbol) ||
!int.TryParse(rankingSymbol.Name.ToString(), out rank))
if (!TryGetRankingSymbol(symbol, out var rankingSymbol) ||
!int.TryParse(rankingSymbol.Name.ToString(), out var rank))
{
return 0;
}
......
......@@ -80,10 +80,8 @@ public override Task<Stream> ReadStreamAsync(Document document, string name, Can
return SpecializedTasks.Default<Stream>();
}
int nameId;
EsentStorage.Key key;
if (!TryGetProjectAndDocumentKey(document, out key) ||
!TryGetUniqueNameId(name, out nameId))
if (!TryGetProjectAndDocumentKey(document, out var key) ||
!TryGetUniqueNameId(name, out var nameId))
{
return SpecializedTasks.Default<Stream>();
}
......@@ -101,10 +99,8 @@ public override Task<Stream> ReadStreamAsync(Project project, string name, Cance
return SpecializedTasks.Default<Stream>();
}
int nameId;
EsentStorage.Key key;
if (!TryGetProjectKey(project, out key) ||
!TryGetUniqueNameId(name, out nameId))
if (!TryGetProjectKey(project, out var key) ||
!TryGetUniqueNameId(name, out var nameId))
{
return SpecializedTasks.Default<Stream>();
}
......@@ -122,8 +118,7 @@ public override Task<Stream> ReadStreamAsync(string name, CancellationToken canc
return SpecializedTasks.Default<Stream>();
}
int nameId;
if (!TryGetUniqueNameId(name, out nameId))
if (!TryGetUniqueNameId(name, out var nameId))
{
return SpecializedTasks.Default<Stream>();
}
......@@ -172,10 +167,8 @@ public override Task<bool> WriteStreamAsync(Document document, string name, Stre
return SpecializedTasks.False;
}
int nameId;
EsentStorage.Key key;
if (!TryGetProjectAndDocumentKey(document, out key) ||
!TryGetUniqueNameId(name, out nameId))
if (!TryGetProjectAndDocumentKey(document, out var key) ||
!TryGetUniqueNameId(name, out var nameId))
{
return SpecializedTasks.False;
}
......@@ -194,10 +187,8 @@ public override Task<bool> WriteStreamAsync(Project project, string name, Stream
return SpecializedTasks.False;
}
int nameId;
EsentStorage.Key key;
if (!TryGetProjectKey(project, out key) ||
!TryGetUniqueNameId(name, out nameId))
if (!TryGetProjectKey(project, out var key) ||
!TryGetUniqueNameId(name, out var nameId))
{
return SpecializedTasks.False;
}
......@@ -216,8 +207,7 @@ public override Task<bool> WriteStreamAsync(string name, Stream stream, Cancella
return SpecializedTasks.False;
}
int nameId;
if (!TryGetUniqueNameId(name, out nameId))
if (!TryGetUniqueNameId(name, out var nameId))
{
return SpecializedTasks.False;
}
......@@ -337,12 +327,8 @@ private EsentStorage.ProjectDocumentTableAccessor GetAccessor(EsentStorage.Key k
private bool TryGetProjectAndDocumentKey(Document document, out EsentStorage.Key key)
{
key = default(EsentStorage.Key);
int projectId;
int projectNameId;
int documentId;
if (!TryGetProjectId(document.Project, out projectId, out projectNameId) ||
!TryGetUniqueFileId(document.FilePath, out documentId))
if (!TryGetProjectId(document.Project, out var projectId, out var projectNameId) ||
!TryGetUniqueFileId(document.FilePath, out var documentId))
{
return false;
}
......@@ -354,10 +340,7 @@ private bool TryGetProjectAndDocumentKey(Document document, out EsentStorage.Key
private bool TryGetProjectKey(Project project, out EsentStorage.Key key)
{
key = default(EsentStorage.Key);
int projectId;
int projectNameId;
if (!TryGetProjectId(project, out projectId, out projectNameId))
if (!TryGetProjectId(project, out var projectId, out var projectNameId))
{
return false;
}
......
......@@ -65,8 +65,7 @@ private VersionStamp GetIdentifierSetVersion(EsentStorage.Key key)
return VersionStamp.Default;
}
int identifierId;
if (!TryGetIdentifierSetVersionId(out identifierId))
if (!TryGetIdentifierSetVersionId(out var identifierId))
{
return VersionStamp.Default;
}
......@@ -99,8 +98,7 @@ public VersionStamp GetIdentifierSetVersion(Document document)
return VersionStamp.Default;
}
EsentStorage.Key key;
if (!TryGetProjectAndDocumentKey(document, out key))
if (!TryGetProjectAndDocumentKey(document, out var key))
{
return VersionStamp.Default;
}
......@@ -117,9 +115,7 @@ public bool ReadIdentifierPositions(Document document, VersionStamp syntaxVersio
return false;
}
int identifierId;
EsentStorage.Key key;
if (!TryGetProjectAndDocumentKey(document, out key))
if (!TryGetProjectAndDocumentKey(document, out var key))
{
return false;
}
......@@ -130,7 +126,7 @@ public bool ReadIdentifierPositions(Document document, VersionStamp syntaxVersio
return false;
}
if (!TryGetUniqueIdentifierId(identifier, out identifierId))
if (!TryGetUniqueIdentifierId(identifier, out var identifierId))
{
return false;
}
......@@ -180,8 +176,7 @@ public bool WriteIdentifierLocations(Document document, VersionStamp version, Sy
return false;
}
EsentStorage.Key key;
if (!TryGetProjectAndDocumentKey(document, out key))
if (!TryGetProjectAndDocumentKey(document, out var key))
{
return false;
}
......@@ -290,8 +285,7 @@ private void Free(Dictionary<string, List<int>> map)
private bool TrySaveIdentifierSetVersion(
EsentStorage.IdentifierLocationTableAccessor accessor, EsentStorage.Key key, VersionStamp version)
{
int identifierId;
if (!TryGetIdentifierSetVersionId(out identifierId))
if (!TryGetIdentifierSetVersionId(out var identifierId))
{
return false;
}
......
......@@ -73,8 +73,7 @@ public void Close()
private JET_DBID OpenExistingDatabase(JET_SESID session, string databaseFile)
{
JET_DBID databaseId;
Api.JetOpenDatabase(SessionId, databaseFile, null, out databaseId, OpenDatabaseGrbit.None);
Api.JetOpenDatabase(SessionId, databaseFile, null, out var databaseId, OpenDatabaseGrbit.None);
return databaseId;
}
......
......@@ -144,8 +144,7 @@ private AbstractTableAccessor GetTableAccessor(TableKinds tableKind)
private OpenSession GetOpenSession()
{
OpenSession session;
if (_sessionCache.TryPop(out session))
if (_sessionCache.TryPop(out var session))
{
return session;
}
......@@ -223,9 +222,7 @@ private Instance CreateEsentInstance()
private void TryInitializeGlobalParameters()
{
int instances;
JET_INSTANCE_INFO[] infos;
Api.JetGetInstanceInfo(out instances, out infos);
Api.JetGetInstanceInfo(out var instances, out var infos);
// already initialized nothing we can do.
if (instances != 0)
......
......@@ -30,9 +30,7 @@ public DocumentationProvider GetDocumentationProvider(string assemblyPath)
}
assemblyPath = Path.ChangeExtension(assemblyPath, "xml");
DocumentationProvider provider;
if (!_assemblyPathToDocumentationProviderMap.TryGetValue(assemblyPath, out provider))
if (!_assemblyPathToDocumentationProviderMap.TryGetValue(assemblyPath, out var provider))
{
provider = _assemblyPathToDocumentationProviderMap.GetOrAdd(assemblyPath, _path => XmlDocumentationProvider.CreateFromFile(_path));
}
......
......@@ -64,9 +64,8 @@ protected internal override HostWorkspaceServices CreateWorkspaceServices(Worksp
/// </summary>
public IEnumerable<Lazy<TExtension, TMetadata>> GetExports<TExtension, TMetadata>()
{
IEnumerable exports;
var key = new ExportKey(typeof(TExtension).AssemblyQualifiedName, typeof(TMetadata).AssemblyQualifiedName);
if (!_exportsMap.TryGetValue(key, out exports))
if (!_exportsMap.TryGetValue(key, out var exports))
{
exports = ImmutableInterlocked.GetOrAdd(ref _exportsMap, key, _ =>
{
......@@ -82,9 +81,8 @@ protected internal override HostWorkspaceServices CreateWorkspaceServices(Worksp
/// </summary>
public IEnumerable<Lazy<TExtension>> GetExports<TExtension>()
{
IEnumerable exports;
var key = new ExportKey(typeof(TExtension).AssemblyQualifiedName, "");
if (!_exportsMap.TryGetValue(key, out exports))
if (!_exportsMap.TryGetValue(key, out var exports))
{
exports = ImmutableInterlocked.GetOrAdd(ref _exportsMap, key, _ =>
_exportProvider.GetExports<TExtension>().ToImmutableArray());
......
......@@ -181,10 +181,7 @@ private void InitializeFromModel(CSharpCompilerInputs compilerInputs, MSB.Execut
compilerInputs.SetAnalyzers(this.GetAnalyzerReferencesFromModel(executedProject).ToArray());
compilerInputs.SetAdditionalFiles(this.GetAdditionalFilesFromModel(executedProject).ToArray());
compilerInputs.SetSources(this.GetDocumentsFromModel(executedProject).ToArray());
string errorMessage;
int errorCode;
compilerInputs.EndInitialization(out errorMessage, out errorCode);
compilerInputs.EndInitialization(out var errorMessage, out var errorCode);
}
private class CSharpCompilerInputs :
......
......@@ -152,8 +152,7 @@ private void SetSolutionProperties(string solutionFilePath)
var projectAbsolutePath = TryGetAbsolutePath(project.AbsolutePath, reportMode);
if (projectAbsolutePath != null)
{
IProjectFileLoader loader;
if (TryGetLoaderFromProjectPath(projectAbsolutePath, reportMode, out loader))
if (TryGetLoaderFromProjectPath(projectAbsolutePath, reportMode, out var loader))
{
// projects get added to 'loadedProjects' as side-effect
// never prefer metadata when loading solution, all projects get loaded if they can.
......@@ -202,11 +201,8 @@ internal string GetAbsoluteSolutionPath(string path, string baseDirectory)
throw new ArgumentNullException(nameof(projectFilePath));
}
string fullPath;
this.TryGetAbsoluteProjectPath(projectFilePath, Directory.GetCurrentDirectory(), ReportMode.Throw, out fullPath);
IProjectFileLoader loader;
this.TryGetLoaderFromProjectPath(projectFilePath, ReportMode.Throw, out loader);
this.TryGetAbsoluteProjectPath(projectFilePath, Directory.GetCurrentDirectory(), ReportMode.Throw, out var fullPath);
this.TryGetLoaderFromProjectPath(projectFilePath, ReportMode.Throw, out var loader);
var loadedProjects = new LoadState(projectPathToProjectIdMap);
var id = await this.LoadProjectAsync(fullPath, loader, this.LoadMetadataForReferencedProjects, loadedProjects, cancellationToken).ConfigureAwait(false);
......@@ -253,21 +249,16 @@ public void Add(ProjectInfo info)
/// </summary>
public bool ProjectAlreadyReferencesProject(ProjectId fromProject, ProjectId targetProject)
{
Dictionary<ProjectId, bool> fromProjectMemo;
if ( !_projectAlreadyReferencesProjectResultCache.TryGetValue(fromProject, out fromProjectMemo))
if ( !_projectAlreadyReferencesProjectResultCache.TryGetValue(fromProject, out var fromProjectMemo))
{
fromProjectMemo = new Dictionary<ProjectId, bool>();
_projectAlreadyReferencesProjectResultCache.Add(fromProject, fromProjectMemo);
}
bool answer;
if ( !fromProjectMemo.TryGetValue(targetProject, out answer))
if ( !fromProjectMemo.TryGetValue(targetProject, out var answer))
{
ProjectInfo info;
answer =
_projectIdToProjectInfoMap.TryGetValue(fromProject, out info) &&
_projectIdToProjectInfoMap.TryGetValue(fromProject, out var info) &&
info.ProjectReferences.Any(pr =>
pr.ProjectId == targetProject ||
ProjectAlreadyReferencesProject(pr.ProjectId, targetProject)
......@@ -285,15 +276,13 @@ public IEnumerable<ProjectInfo> Projects
public ProjectId GetProjectId(string fullProjectPath)
{
ProjectId id;
_projectPathToProjectIdMap.TryGetValue(fullProjectPath, out id);
_projectPathToProjectIdMap.TryGetValue(fullProjectPath, out var id);
return id;
}
public ProjectId GetOrCreateProjectId(string fullProjectPath)
{
ProjectId id;
if (!_projectPathToProjectIdMap.TryGetValue(fullProjectPath, out id))
if (!_projectPathToProjectIdMap.TryGetValue(fullProjectPath, out var id))
{
id = ProjectId.CreateNewId(debugName: fullProjectPath);
_projectPathToProjectIdMap.Add(fullProjectPath, id);
......@@ -376,9 +365,7 @@ private async Task<ProjectId> LoadProjectAsync(string projectFilePath, IProjectF
var docs = new List<DocumentInfo>();
foreach (var docFileInfo in docFileInfos)
{
string name;
ImmutableArray<string> folders;
GetDocumentNameAndFolders(docFileInfo.LogicalPath, out name, out folders);
GetDocumentNameAndFolders(docFileInfo.LogicalPath, out var name, out var folders);
docs.Add(DocumentInfo.Create(
DocumentId.CreateNewId(projectId, debugName: docFileInfo.FilePath),
......@@ -393,9 +380,7 @@ private async Task<ProjectId> LoadProjectAsync(string projectFilePath, IProjectF
var additionalDocs = new List<DocumentInfo>();
foreach (var docFileInfo in additionalDocFileInfos)
{
string name;
ImmutableArray<string> folders;
GetDocumentNameAndFolders(docFileInfo.LogicalPath, out name, out folders);
GetDocumentNameAndFolders(docFileInfo.LogicalPath, out var name, out var folders);
additionalDocs.Add(DocumentInfo.Create(
DocumentId.CreateNewId(projectId, debugName: docFileInfo.FilePath),
......@@ -523,9 +508,7 @@ private class ResolvedReferences
foreach (var projectFileReference in projectFileReferences)
{
string fullPath;
if (TryGetAbsoluteProjectPath(projectFileReference.Path, Path.GetDirectoryName(thisProjectPath), reportMode, out fullPath))
if (TryGetAbsoluteProjectPath(projectFileReference.Path, Path.GetDirectoryName(thisProjectPath), reportMode, out var fullPath))
{
// if the project is already loaded, then just reference the one we have
var existingProjectId = loadedProjects.GetProjectId(fullPath);
......@@ -535,8 +518,7 @@ private class ResolvedReferences
continue;
}
IProjectFileLoader loader;
TryGetLoaderFromProjectPath(fullPath, ReportMode.Ignore, out loader);
TryGetLoaderFromProjectPath(fullPath, ReportMode.Ignore, out var loader);
// get metadata if preferred or if loader is unknown
if (preferMetadata || loader == null)
......@@ -668,8 +650,7 @@ private bool TryGetLoaderFromProjectPath(string projectFilePath, ReportMode mode
extension = extension.Substring(1);
}
string language;
if (_extensionToLanguageMap.TryGetValue(extension, out language))
if (_extensionToLanguageMap.TryGetValue(extension, out var language))
{
if (_workspace.Services.SupportedLanguages.Contains(language))
{
......
......@@ -262,8 +262,7 @@ protected override void ApplyProjectChanges(ProjectChanges projectChanges)
if (this.HasProjectFileChanges(projectChanges))
{
var projectPath = project.FilePath;
IProjectFileLoader loader;
if (_loader.TryGetLoaderFromProjectPath(projectPath, out loader))
if (_loader.TryGetLoaderFromProjectPath(projectPath, out var loader))
{
try
{
......@@ -343,9 +342,7 @@ protected override void ApplyDocumentAdded(DocumentInfo info, SourceText text)
System.Diagnostics.Debug.Assert(_applyChangesProjectFile != null);
var project = this.CurrentSolution.GetProject(info.Id.ProjectId);
IProjectFileLoader loader;
if (_loader.TryGetLoaderFromProjectPath(project.FilePath, out loader))
if (_loader.TryGetLoaderFromProjectPath(project.FilePath, out var loader))
{
var extension = _applyChangesProjectFile.GetDocumentExtension(info.SourceCodeKind);
var fileName = Path.ChangeExtension(info.Name, extension);
......
......@@ -160,8 +160,7 @@ private static IEnumerable<string> SplitTargets(string targets)
private static IEnumerable<string> GetTargetDependents(MSB.Evaluation.Project project, string targetName)
{
MSB.Execution.ProjectTargetInstance targetInstance;
if (project.Targets.TryGetValue(targetName, out targetInstance))
if (project.Targets.TryGetValue(targetName, out var targetInstance))
{
return SplitTargets(project.ExpandString(targetInstance.DependsOnTargets));
}
......
......@@ -305,8 +305,7 @@ private static int ConvertToInt(string value)
}
else
{
int result;
int.TryParse(value, out result);
int.TryParse(value, out var result);
return result;
}
}
......@@ -329,8 +328,7 @@ private static ulong ConvertToULong(string value)
}
else
{
ulong result;
ulong.TryParse(value, out result);
ulong.TryParse(value, out var result);
return result;
}
}
......@@ -356,8 +354,7 @@ private static ulong ConvertToULong(string value)
}
else
{
TEnum result;
if (Enum.TryParse<TEnum>(value, out result))
if (Enum.TryParse<TEnum>(value, out var result))
{
return result;
}
......
......@@ -86,8 +86,7 @@ public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reason
return;
}
long size;
if (_map.TryGetValue(document.Id, out size))
if (_map.TryGetValue(document.Id, out var size))
{
if (size == length)
{
......@@ -105,8 +104,7 @@ public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reason
public void RemoveDocument(DocumentId documentId)
{
long size;
if (_map.TryRemove(documentId, out size))
if (_map.TryRemove(documentId, out var size))
{
Interlocked.Add(ref _size, -size);
}
......
......@@ -101,8 +101,7 @@ private IPersistentStorage GetStorage(Solution solution, string workingFolderPat
lock (_lookupAccessLock)
{
// see whether we have something we can use
AbstractPersistentStorage storage;
if (_lookup.TryGetValue(solution.FilePath, out storage))
if (_lookup.TryGetValue(solution.FilePath, out var storage))
{
// previous attempt to create esent storage failed.
if (storage == null && !SolutionSizeAboveThreshold(solution))
......@@ -202,8 +201,7 @@ private string GetWorkingFolderPath(Solution solution)
private AbstractPersistentStorage TryCreateEsentStorage(string workingFolderPath, string solutionPath)
{
AbstractPersistentStorage esentStorage;
if (TryCreateEsentStorage(workingFolderPath, solutionPath, out esentStorage))
if (TryCreateEsentStorage(workingFolderPath, solutionPath, out var esentStorage))
{
return esentStorage;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册