提交 84678e08 编写于 作者: C Cyrus Najmabadi

use 'var'

上级 ab2aebb5
......@@ -18,7 +18,7 @@ public static unsafe IntPtr CreateWrapper()
public static unsafe void SetInnerObject(IntPtr wrapperUnknown, IntPtr innerUnknown, IntPtr managedObjectGCHandlePtr)
{
BlindAggregator* pWrapper = (BlindAggregator*)wrapperUnknown;
var pWrapper = (BlindAggregator*)wrapperUnknown;
pWrapper->SetInnerObject(innerUnknown, managedObjectGCHandlePtr);
}
......@@ -35,7 +35,7 @@ private struct BlindAggregator
public static unsafe BlindAggregator* CreateInstance()
{
BlindAggregator* pResult = (BlindAggregator*)Marshal.AllocCoTaskMem(sizeof(BlindAggregator));
var pResult = (BlindAggregator*)Marshal.AllocCoTaskMem(sizeof(BlindAggregator));
if (pResult != null)
{
pResult->Construct();
......@@ -163,7 +163,7 @@ private static unsafe uint AddRef(BlindAggregator* pThis)
private static unsafe uint Release(BlindAggregator* pThis)
{
uint result = unchecked((uint)Interlocked.Decrement(ref pThis->_refCount));
var result = unchecked((uint)Interlocked.Decrement(ref pThis->_refCount));
if (result == 0u)
{
pThis->FinalRelease();
......
......@@ -133,7 +133,7 @@ private string GetSignatureDescriptionString(int[] signature, int? totalParamete
if (totalParameters.HasValue)
{
var removed = new List<int>();
for (int i = 0; i < totalParameters; i++)
for (var i = 0; i < totalParameters; i++)
{
if (!signature.Contains(i))
{
......@@ -180,9 +180,9 @@ public async Task TestAllSignatureChangesAsync(string languageName, string marku
private IEnumerable<int[]> GetAllSignatureSpecifications(int[] signaturePartCounts)
{
int regularParameterStartIndex = signaturePartCounts[0];
int defaultValueParameterStartIndex = signaturePartCounts[0] + signaturePartCounts[1];
int paramParameterIndex = signaturePartCounts[0] + signaturePartCounts[1] + signaturePartCounts[2];
var regularParameterStartIndex = signaturePartCounts[0];
var defaultValueParameterStartIndex = signaturePartCounts[0] + signaturePartCounts[1];
var paramParameterIndex = signaturePartCounts[0] + signaturePartCounts[1] + signaturePartCounts[2];
var regularParameterArrangements = GetPermutedSubsets(regularParameterStartIndex, signaturePartCounts[1]);
var defaultValueParameterArrangements = GetPermutedSubsets(defaultValueParameterStartIndex, signaturePartCounts[2]);
......@@ -223,8 +223,8 @@ private IEnumerable<IEnumerable<int>> GetPermutations(IEnumerable<int> list)
yield break;
}
int index = 0;
foreach (int element in list)
var index = 0;
foreach (var element in list)
{
var permutationsWithoutElement = GetPermutations(GetListWithoutElementAtIndex(list, index));
foreach (var perm in permutationsWithoutElement)
......@@ -238,7 +238,7 @@ private IEnumerable<IEnumerable<int>> GetPermutations(IEnumerable<int> list)
private IEnumerable<int> GetListWithoutElementAtIndex(IEnumerable<int> list, int skippedIndex)
{
int index = 0;
var index = 0;
foreach (var x in list)
{
if (index != skippedIndex)
......
......@@ -33,7 +33,7 @@ private static string GetText(ClassifiedSpan tuple)
actualClassificationList.Sort((t1, t2) => t1.TextSpan.Start - t2.TextSpan.Start);
var max = Math.Max(expectedClassificationList.Count, actualClassificationList.Count);
for (int i = 0; i < max; i++)
for (var i = 0; i < max; i++)
{
if (i >= expectedClassificationList.Count)
{
......
......@@ -663,7 +663,7 @@ protected static (OptionKey, object) SingleOption<T>(PerLanguageOption<CodeStyle
TestParameters parameters,
params string[] outputs)
{
for (int index = 0; index < outputs.Length; index++)
for (var index = 0; index < outputs.Length; index++)
{
var output = outputs[index];
await TestInRegularAndScript1Async(input, output, index, parameters: parameters);
......
......@@ -454,7 +454,7 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace)
var textBuffer = WorkspaceFixture.CurrentDocument.TextBuffer;
string actualCodeAfterCommit = textBuffer.CurrentSnapshot.AsText().ToString();
var actualCodeAfterCommit = textBuffer.CurrentSnapshot.AsText().ToString();
var caretPosition = commit.NewPosition != null ? commit.NewPosition.Value : textView.Caret.Position.BufferPosition.Position;
Assert.Equal(actualExpectedCode, actualCodeAfterCommit);
......@@ -483,7 +483,7 @@ protected virtual void SetWorkspaceOptions(TestWorkspace workspace)
customCommitCompletionProvider.Commit(completionItem, textView, textBuffer, textView.TextSnapshot, commitChar);
string actualCodeAfterCommit = textBuffer.CurrentSnapshot.AsText().ToString();
var actualCodeAfterCommit = textBuffer.CurrentSnapshot.AsText().ToString();
var caretPosition = textView.Caret.Position.BufferPosition.Position;
Assert.Equal(actualExpectedCode, actualCodeAfterCommit);
......
......@@ -162,7 +162,7 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri
return (ImmutableArray<Diagnostic>.Empty, ImmutableArray<CodeAction>.Empty, null);
}
FixAllScope? scope = GetFixAllScope(annotation);
var scope = GetFixAllScope(annotation);
return await GetDiagnosticAndFixesAsync(
diagnostics, fixer, testDriver, document, span, scope, index);
}
......
......@@ -13,17 +13,17 @@ public static class DirectoryExtensions
/// <param name="path">The directory path to delete</param>
public static void DeleteRecursively(string path)
{
string[] files = Directory.GetFiles(path);
string[] dirs = Directory.GetDirectories(path);
var files = Directory.GetFiles(path);
var dirs = Directory.GetDirectories(path);
foreach (string file in files)
foreach (var file in files)
{
// If there were read-only attributes on the file, the delete would throw, so set normal permissions.
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (string dir in dirs)
foreach (var dir in dirs)
{
DeleteRecursively(dir);
}
......
......@@ -105,7 +105,7 @@ private static IEnumerable<(TextSpan Span, int[] Ids)> GetSpansRecursive(Regex r
{
var markedSyntax = match.Groups[contentGroupName];
var ids = GetIds(match.Groups["Id"].Value);
int absoluteOffset = offset + markedSyntax.Index;
var absoluteOffset = offset + markedSyntax.Index;
var span = markedSyntax.Length != 0 ? new TextSpan(absoluteOffset, markedSyntax.Length) : new TextSpan();
yield return (span, ids);
......@@ -121,7 +121,7 @@ internal static IEnumerable<(TextSpan Span, int Id)> GetActiveSpans(string marke
{
foreach (var (span, ids) in GetSpansRecursive(s_activeStatementPattern, "ActiveStatement", markedSource, offset: 0))
{
foreach (int id in ids)
foreach (var id in ids)
{
yield return (span, id);
}
......@@ -156,10 +156,10 @@ internal static ActiveStatement CreateActiveStatement(TextSpan span, int id, Sou
var result = new TextSpan?[count];
for (int i = 0; i < matches.Count; i++)
for (var i = 0; i < matches.Count; i++)
{
var span = matches[i].Groups["TrackingStatement"];
foreach (int id in GetIds(matches[i]))
foreach (var id in GetIds(matches[i]))
{
result[id] = new TextSpan(span.Index, span.Length);
}
......@@ -173,7 +173,7 @@ internal static ImmutableArray<TextSpan>[] GetExceptionRegions(string src, int a
var matches = ExceptionRegionPattern.Matches(src);
var result = new List<TextSpan>[activeStatementCount];
for (int i = 0; i < matches.Count; i++)
for (var i = 0; i < matches.Count; i++)
{
var exceptionRegion = matches[i].Groups["ExceptionRegion"];
......
......@@ -21,7 +21,7 @@ public SyntaxMapDescription(string oldSource, string newSource)
NewSpans = GetSpans(newSource);
Assert.Equal(OldSpans.Length, NewSpans.Length);
for (int i = 0; i < OldSpans.Length; i++)
for (var i = 0; i < OldSpans.Length; i++)
{
Assert.Equal(OldSpans[i].Length, NewSpans[i].Length);
}
......@@ -37,7 +37,7 @@ internal static ImmutableArray<ImmutableArray<TextSpan>> GetSpans(string src)
var matches = s_statementPattern.Matches(src);
var result = new List<List<TextSpan>>();
for (int i = 0; i < matches.Count; i++)
for (var i = 0; i < matches.Count; i++)
{
var stmt = matches[i].Groups["Node"];
var id = matches[i].Groups["Id"].Value.Split('.');
......@@ -62,7 +62,7 @@ internal static ImmutableArray<ImmutableArray<TextSpan>> GetSpans(string src)
{
get
{
for (int j = 0; j < OldSpans[i].Length; j++)
for (var j = 0; j < OldSpans[i].Length; j++)
{
yield return KeyValuePairUtil.Create(OldSpans[i][j], NewSpans[i][j]);
}
......
......@@ -38,7 +38,7 @@ internal abstract class EditAndContinueTestHelpers
tree.GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error).Verify();
DocumentId documentId = DocumentId.CreateNewId(ProjectId.CreateNewId("TestEnCProject"), "TestEnCDocument");
var documentId = DocumentId.CreateNewId(ProjectId.CreateNewId("TestEnCProject"), "TestEnCDocument");
TestActiveStatementTrackingService trackingService;
if (trackingSpansOpt != null)
......@@ -67,7 +67,7 @@ internal abstract class EditAndContinueTestHelpers
// check new exception regions:
Assert.Equal(expectedNewExceptionRegions.Length, actualNewExceptionRegions.Length);
for (int i = 0; i < expectedNewExceptionRegions.Length; i++)
for (var i = 0; i < expectedNewExceptionRegions.Length; i++)
{
AssertSpansEqual(expectedNewExceptionRegions[i], actualNewExceptionRegions[i], source, text);
}
......@@ -85,8 +85,8 @@ internal abstract class EditAndContinueTestHelpers
Assert.Equal(oldActiveStatements.Length, description.OldTrackingSpans.Length);
}
string newSource = editScript.Match.NewRoot.SyntaxTree.ToString();
string oldSource = editScript.Match.OldRoot.SyntaxTree.ToString();
var newSource = editScript.Match.NewRoot.SyntaxTree.ToString();
var oldSource = editScript.Match.OldRoot.SyntaxTree.ToString();
var oldText = SourceText.From(oldSource);
var newText = SourceText.From(newSource);
......@@ -97,7 +97,7 @@ internal abstract class EditAndContinueTestHelpers
var updatedActiveMethodMatches = new List<AbstractEditAndContinueAnalyzer.UpdatedMemberInfo>();
var editMap = Analyzer.BuildEditMap(editScript);
DocumentId documentId = DocumentId.CreateNewId(ProjectId.CreateNewId("TestEnCProject"), "TestEnCDocument");
var documentId = DocumentId.CreateNewId(ProjectId.CreateNewId("TestEnCProject"), "TestEnCDocument");
TestActiveStatementTrackingService trackingService;
if (description.OldTrackingSpans != null)
......@@ -130,7 +130,7 @@ internal abstract class EditAndContinueTestHelpers
if (diagnostics.Count == 0)
{
// check old exception regions:
for (int i = 0; i < oldActiveStatements.Length; i++)
for (var i = 0; i < oldActiveStatements.Length; i++)
{
var actualOldExceptionRegions = Analyzer.GetExceptionRegions(
oldText,
......@@ -144,14 +144,14 @@ internal abstract class EditAndContinueTestHelpers
// check new exception regions:
Assert.Equal(description.NewRegions.Length, actualNewExceptionRegions.Length);
for (int i = 0; i < description.NewRegions.Length; i++)
for (var i = 0; i < description.NewRegions.Length; i++)
{
AssertSpansEqual(description.NewRegions[i], actualNewExceptionRegions[i], newSource, newText);
}
}
else
{
for (int i = 0; i < oldActiveStatements.Length; i++)
for (var i = 0; i < oldActiveStatements.Length; i++)
{
Assert.Equal(0, description.NewRegions[i].Length);
}
......@@ -170,8 +170,8 @@ internal abstract class EditAndContinueTestHelpers
IEnumerable<string> expectedNodeUpdates,
RudeEditDiagnosticDescription[] expectedDiagnostics)
{
string newSource = editScript.Match.NewRoot.SyntaxTree.ToString();
string oldSource = editScript.Match.OldRoot.SyntaxTree.ToString();
var newSource = editScript.Match.NewRoot.SyntaxTree.ToString();
var oldSource = editScript.Match.OldRoot.SyntaxTree.ToString();
var oldText = SourceText.From(oldSource);
var newText = SourceText.From(newSource);
......@@ -303,7 +303,7 @@ internal abstract class EditAndContinueTestHelpers
Assert.Equal(expectedSemanticEdits.Length, actualSemanticEdits.Count);
for (int i = 0; i < actualSemanticEdits.Count; i++)
for (var i = 0; i < actualSemanticEdits.Count; i++)
{
var editKind = expectedSemanticEdits[i].Kind;
......
......@@ -30,17 +30,17 @@ private static IEnumerable<RudeEditDiagnosticDescription> ToDescription(this IEn
private static string GetLineAt(string source, int position)
{
int start = source.LastIndexOf(LineSeparator, position, position);
int end = source.IndexOf(LineSeparator, position);
var start = source.LastIndexOf(LineSeparator, position, position);
var end = source.IndexOf(LineSeparator, position);
return source.Substring(start + 1, end - start).Trim();
}
public static IEnumerable<string> ToLines(this string str)
{
int i = 0;
var i = 0;
while (true)
{
int eoln = str.IndexOf(LineSeparator, i, StringComparison.Ordinal);
var eoln = str.IndexOf(LineSeparator, i, StringComparison.Ordinal);
if (eoln < 0)
{
yield return str.Substring(i);
......
......@@ -50,7 +50,7 @@ public abstract class AbstractKeywordHighlighterTests
var root = await document.GetSyntaxRootAsync();
for (int i = 0; i <= cursorSpan.Length; i++)
for (var i = 0; i <= cursorSpan.Length; i++)
{
var position = cursorSpan.Start + i;
var highlightSpans = highlighter.GetHighlights(root, position, CancellationToken.None).ToList();
......@@ -63,7 +63,7 @@ public abstract class AbstractKeywordHighlighterTests
private static void CheckSpans(SyntaxTree tree, IList<TextSpan> expectedHighlightSpans, List<TextSpan> highlightSpans)
{
for (int j = 0; j < Math.Max(highlightSpans.Count, expectedHighlightSpans.Count); j++)
for (var j = 0; j < Math.Max(highlightSpans.Count, expectedHighlightSpans.Count); j++)
{
if (j >= expectedHighlightSpans.Count)
{
......
......@@ -154,7 +154,7 @@ internal void InitializeWorkspace(TestWorkspace workspace)
Assert.Equal(expecteditems.Count(), items.Count());
for (int i = 0; i < expecteditems.Count; i++)
for (var i = 0; i < expecteditems.Count; i++)
{
var expectedItem = expecteditems[i];
var actualItem = items.ElementAt(i);
......@@ -201,7 +201,7 @@ internal void InitializeWorkspace(TestWorkspace workspace)
internal BitmapSource CreateIconBitmapSource()
{
int stride = PixelFormats.Bgr32.BitsPerPixel / 8 * 16;
var stride = PixelFormats.Bgr32.BitsPerPixel / 8 * 16;
return BitmapSource.Create(16, 16, 96, 96, PixelFormats.Bgr32, null, new byte[16 * stride], stride);
}
......@@ -209,7 +209,7 @@ internal BitmapSource CreateIconBitmapSource()
// http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.language.navigateto.interfaces.navigatetoitem.aspx
protected static int CompareNavigateToItems(NavigateToItem a, NavigateToItem b)
{
int result = ((int)a.PatternMatch.Kind) - ((int)b.PatternMatch.Kind);
var result = ((int)a.PatternMatch.Kind) - ((int)b.PatternMatch.Kind);
if (result != 0)
{
return result;
......
......@@ -137,7 +137,7 @@ protected virtual void VerifyTriggerCharacters(char[] expectedTriggerCharacters,
private void VerifyTriggerCharactersWorker(char[] expectedTriggerCharacters, char[] unexpectedTriggerCharacters, SourceCodeKind sourceCodeKind)
{
ISignatureHelpProvider signatureHelpProvider = CreateSignatureHelpProvider();
var signatureHelpProvider = CreateSignatureHelpProvider();
foreach (var expectedTriggerCharacter in expectedTriggerCharacters)
{
......@@ -186,7 +186,7 @@ private async Task VerifyCurrentParameterNameWorkerAsync(string markup, string e
{
Assert.Equal(expectedTestItems.Count(), actualSignatureHelpItems.Items.Count());
for (int i = 0; i < expectedTestItems.Count(); i++)
for (var i = 0; i < expectedTestItems.Count(); i++)
{
CompareSigHelpItemsAndCurrentPosition(
actualSignatureHelpItems,
......@@ -208,7 +208,7 @@ private async Task VerifyCurrentParameterNameWorkerAsync(string markup, string e
int cursorPosition,
TextSpan applicableSpan)
{
int currentParameterIndex = -1;
var currentParameterIndex = -1;
if (expectedTestItem.CurrentParameterIndex != null)
{
if (expectedTestItem.CurrentParameterIndex.Value >= 0 && expectedTestItem.CurrentParameterIndex.Value < actualSignatureHelpItem.Parameters.Length)
......@@ -432,7 +432,7 @@ private void CompareSelectedIndex(IEnumerable<SignatureHelpTestItem> expectedOrd
Assert.True(expectedOrderedItemsOrNull.Count(i => i.IsSelected) == 1, "Only one expected item can be marked with 'IsSelected'");
Assert.True(selectedItemIndex != null, "Expected an item to be selected, but no item was actually selected");
int counter = 0;
var counter = 0;
foreach (var item in expectedOrderedItemsOrNull)
{
if (item.IsSelected)
......
......@@ -44,7 +44,7 @@ protected async Task VerifyBlockSpansAsync(string markupCode, params Tuple<strin
Assert.True(expectedRegions.Length == actualRegions.Length, $"Expected {expectedRegions.Length} regions but there were {actualRegions.Length}");
for (int i = 0; i < expectedRegions.Length; i++)
for (var i = 0; i < expectedRegions.Length; i++)
{
AssertRegion(expectedRegions[i], actualRegions[i]);
}
......
......@@ -395,7 +395,7 @@ private static string GetDefaultExtension(OutputKind kind)
private string GetTestOutputFilePath(string filepath)
{
string outputFilePath = @"Z:\";
var outputFilePath = @"Z:\";
try
{
......
......@@ -416,7 +416,7 @@ internal override void SetDocumentContext(DocumentId documentId)
IProjectionEditResolver editResolver = null)
{
GetSpansAndCaretFromSurfaceBufferMarkup(markup, baseDocuments,
out var projectionBufferSpans, out Dictionary<string, ImmutableArray<TextSpan>> mappedSpans, out var mappedCaretLocation);
out var projectionBufferSpans, out var mappedSpans, out var mappedCaretLocation);
var projectionBufferFactory = this.GetService<IProjectionBufferFactoryService>();
var projectionBuffer = projectionBufferFactory.CreateProjectionBuffer(editResolver, projectionBufferSpans, options);
......@@ -578,7 +578,7 @@ internal override void SetDocumentContext(DocumentId documentId)
{
var tempMappedMarkupSpans = new Dictionary<string, ArrayBuilder<TextSpan>>();
foreach (string key in markupSpans.Keys)
foreach (var key in markupSpans.Keys)
{
tempMappedMarkupSpans[key] = ArrayBuilder<TextSpan>.GetInstance();
foreach (var markupSpan in markupSpans[key])
......
......@@ -183,7 +183,7 @@ internal static string GetDefaultTestSourceDocumentName(int index, string extens
var index = 0;
var extension = "";
for (int i = 0; i < files.Length; i++)
for (var i = 0; i < files.Length; i++)
{
if (language == LanguageNames.CSharp)
{
......
......@@ -92,8 +92,8 @@ public static TestWorkspace Create(string xmlDefinition, bool completed = true,
var projectNameToTestHostProject = new Dictionary<string, TestHostProject>();
var projectElementToProjectName = new Dictionary<XElement, string>();
var filePathToTextBufferMap = new Dictionary<string, ITextBuffer>();
int projectIdentifier = 0;
int documentIdentifier = 0;
var projectIdentifier = 0;
var documentIdentifier = 0;
foreach (var projectElement in workspaceElement.Elements(ProjectElementName))
{
......@@ -147,14 +147,14 @@ public static TestWorkspace Create(string xmlDefinition, bool completed = true,
}
}
for (int i = 1; i < submissions.Count; i++)
for (var i = 1; i < submissions.Count; i++)
{
if (submissions[i].CompilationOptions == null)
{
continue;
}
for (int j = i - 1; j >= 0; j--)
for (var j = i - 1; j >= 0; j--)
{
if (submissions[j].CompilationOptions != null)
{
......@@ -265,7 +265,7 @@ public static TestWorkspace Create(string xmlDefinition, bool completed = true,
string filePath;
string projectName = projectElement.Attribute(ProjectNameAttribute)?.Value ?? assemblyName;
var projectName = projectElement.Attribute(ProjectNameAttribute)?.Value ?? assemblyName;
if (projectElement.Attribute(FilePathAttributeName) != null)
{
......@@ -471,7 +471,7 @@ private static string GetAssemblyName(TestWorkspace workspace, XElement projectE
private static string GetLanguage(TestWorkspace workspace, XElement projectElement)
{
string languageName = projectElement.Attribute(LanguageAttributeName).Value;
var languageName = projectElement.Attribute(LanguageAttributeName).Value;
if (!workspace.Services.SupportedLanguages.Contains(languageName))
{
......@@ -660,7 +660,7 @@ private static CompilationOptions CreateCompilationOptions(TestWorkspace workspa
string filePath;
var isLinkFileAttribute = documentElement.Attribute(IsLinkFileAttributeName);
bool isLinkFile = isLinkFileAttribute != null && ((bool?)isLinkFileAttribute).HasValue && ((bool?)isLinkFileAttribute).Value;
var isLinkFile = isLinkFileAttribute != null && ((bool?)isLinkFileAttribute).HasValue && ((bool?)isLinkFileAttribute).Value;
if (isLinkFile)
{
// This is a linked file. Use the filePath and markup from the referenced document.
......@@ -788,7 +788,7 @@ private static MetadataReference CreateMetadataReferenceFromSource(TestWorkspace
var aliasElement = referencedSource.Attribute("Aliases")?.Value;
var aliases = aliasElement != null ? aliasElement.Split(',').Select(s => s.Trim()).ToImmutableArray() : default;
bool includeXmlDocComments = false;
var includeXmlDocComments = false;
var includeXmlDocCommentsAttribute = referencedSource.Attribute(IncludeXmlDocCommentsAttributeName);
if (includeXmlDocCommentsAttribute != null &&
((bool?)includeXmlDocCommentsAttribute).HasValue &&
......@@ -802,9 +802,9 @@ private static MetadataReference CreateMetadataReferenceFromSource(TestWorkspace
private static Compilation CreateCompilation(TestWorkspace workspace, XElement referencedSource)
{
string languageName = GetLanguage(workspace, referencedSource);
var languageName = GetLanguage(workspace, referencedSource);
string assemblyName = "ReferencedAssembly";
var assemblyName = "ReferencedAssembly";
var assemblyNameAttribute = referencedSource.Attribute(AssemblyNameAttributeName);
if (assemblyNameAttribute != null)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册