Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IDE0059: Value assigned to variable is never used #3155

Merged
3 changes: 0 additions & 3 deletions Microsoft.Toolkit.Parsers/Markdown/Blocks/YamlHeaderBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Toolkit.Parsers.Markdown.Helpers;

namespace Microsoft.Toolkit.Parsers.Markdown.Blocks
Expand Down Expand Up @@ -108,8 +107,6 @@ internal static YamlHeaderBlock Parse(string markdown, int start, int end, out i
}

var result = new YamlHeaderBlock();
var keys = new List<string>();
var values = new List<string>();
result.Children = new Dictionary<string, string>();
foreach (var item in elements)
{
Expand Down
4 changes: 1 addition & 3 deletions Microsoft.Toolkit.Parsers/Markdown/Inlines/ImageInline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ internal static void AddTripChars(List<InlineTripCharHelper> tripCharHelpers)
/// <returns> A parsed markdown image, or <c>null</c> if this is not a markdown image. </returns>
internal static InlineParseResult Parse(string markdown, int start, int end)
{
int refstart = 0;

// Expect a '!' character.
if (start >= end || markdown[start] != '!')
{
Expand Down Expand Up @@ -120,7 +118,7 @@ internal static InlineParseResult Parse(string markdown, int start, int end)

if (pos < end && markdown[pos] == '[')
{
refstart = pos;
var refstart = pos;
vgromfeld marked this conversation as resolved.
Show resolved Hide resolved

// Find the reference ']' character
while (pos < end)
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Toolkit.Parsers/Markdown/MarkdownDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public MarkdownDocument()
/// <param name="markdownText"> The markdown text. </param>
public void Parse(string markdownText)
{
Blocks = Parse(markdownText, 0, markdownText.Length, quoteDepth: 0, actualEnd: out int actualEnd);
Blocks = Parse(markdownText, 0, markdownText.Length, quoteDepth: 0, actualEnd: out _);
vgromfeld marked this conversation as resolved.
Show resolved Hide resolved

// Remove any references from the list of blocks, and add them to a dictionary.
for (int i = Blocks.Count - 1; i >= 0; i--)
Expand Down
12 changes: 5 additions & 7 deletions Microsoft.Toolkit.Parsers/Rss/RssHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ public static string TimeZoneToOffset(string tz)

tz = tz.ToUpper().Trim();

if (timeZones.ContainsKey(tz))
if (TimeZones.ContainsKey(tz))
{
return timeZones[tz].First();
return TimeZones[tz].First();
}

return null;
Expand All @@ -337,8 +337,7 @@ private static IEnumerable<string> GetImagesInHTMLString(string htmlString)
if (matchHeight.Success)
{
var heightValue = matchHeight.Groups["height"].Value;
int size = 0;
if (int.TryParse(heightValue, out size) && size < 10)
if (int.TryParse(heightValue, out var heightIntValue) && heightIntValue < 10)
{
include = false;
}
Expand All @@ -348,8 +347,7 @@ private static IEnumerable<string> GetImagesInHTMLString(string htmlString)
if (matchWidth.Success)
{
var widthValue = matchWidth.Groups["width"].Value;
int size = 0;
if (int.TryParse(widthValue, out size) && size < 10)
if (int.TryParse(widthValue, out var widthIntValue) && widthIntValue < 10)
{
include = false;
}
Expand All @@ -376,7 +374,7 @@ private static IEnumerable<string> GetImagesInHTMLString(string htmlString)
/// <summary>
/// Dictionary of timezones.
/// </summary>
private static Dictionary<string, string[]> timeZones = new Dictionary<string, string[]>
private static readonly Dictionary<string, string[]> TimeZones = new Dictionary<string, string[]>
{
{ "ACDT", new[] { "-1030", "Australian Central Daylight" } },
{ "ACST", new[] { "-0930", "Australian Central Standard" } },
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Toolkit.Services/OAuth/OAuthParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override string ToString()
/// <returns>Formatted string of key / value.</returns>
public string ToString(bool withQuotes)
{
string format = null;
string format;
if (withQuotes)
{
format = "{0}=\"{1}\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ObservableGattDeviceService(GattDeviceService service)
Service = service;
Name = GattUuidsService.ConvertUuidToName(service.Uuid);
UUID = Service.Uuid.ToString();
var t = GetAllCharacteristics();
PopulateAllCharacteristicsAsync();
}

/// <summary>
Expand Down Expand Up @@ -147,10 +147,9 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
}

/// <summary>
/// Gets all the characteristics of this service
/// Populate the characteristics in <see cref="Characteristics"/>.
/// </summary>
/// <returns>The status of the communication with the GATT device.</returns>
private async Task<GattCommunicationStatus> GetAllCharacteristics()
private async void PopulateAllCharacteristicsAsync()
vgromfeld marked this conversation as resolved.
Show resolved Hide resolved
{
var tokenSource = new CancellationTokenSource(5000);
var getCharacteristicsTask = await Task.Run(
Expand All @@ -167,8 +166,6 @@ private async Task<GattCommunicationStatus> GetAllCharacteristics()
Characteristics.Add(new ObservableGattCharacteristics(gattCharacteristic, this));
}
}

return result.Status;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public static bool IsRunningAsUwp()
else
{
int length = 0;
StringBuilder sb = new StringBuilder(0);
int result = GetCurrentPackageFullName(ref length, sb);
var sb = new StringBuilder(0);
GetCurrentPackageFullName(ref length, sb);

sb = new StringBuilder(length);
result = GetCurrentPackageFullName(ref length, sb);
var result = GetCurrentPackageFullName(ref length, sb);
vgromfeld marked this conversation as resolved.
Show resolved Hide resolved

_isRunningAsUwp = result != APPMODEL_ERROR_NO_PACKAGE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Toolkit.Uwp.Notifications
{
Expand Down Expand Up @@ -198,8 +197,8 @@ public ToastContentBuilder AddComboBox(string id, string title, string defaultSe

for (int i = 0; i < choices.Count(); i++)
{
var choice = choices.ElementAt(i);
box.Items.Add(new ToastSelectionBoxItem(choice.comboBoxItemId, choice.comboBoxItemContent));
var (comboBoxItemId, comboBoxItemContent) = choices.ElementAt(i);
box.Items.Add(new ToastSelectionBoxItem(comboBoxItemId, comboBoxItemContent));
}

return AddToastInput(box);
Expand All @@ -208,7 +207,7 @@ public ToastContentBuilder AddComboBox(string id, string title, string defaultSe
/// <summary>
/// Add an input option to the Toast.
/// </summary>
/// <param name="input">An instance of a class that impmement <see cref="IToastInput"/> that will be used on the toast.</param>
/// <param name="input">An instance of a class that implement <see cref="IToastInput"/> that will be used on the toast.</param>
/// <returns>The current instance of <see cref="ToastContentBuilder"/></returns>
public ToastContentBuilder AddToastInput(IToastInput input)
{
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Toolkit.Uwp.Notifications/Toasts/ToastPeople.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed class ToastPeople

internal void PopulateToastElement(Element_Toast toast)
{
string hintPeople = null;
string hintPeople;

if (RemoteId != null)
{
Expand Down
8 changes: 2 additions & 6 deletions Microsoft.Toolkit.Uwp.PlatformDifferencesGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,11 @@ public static string AssemblyDirectory

private static Dictionary<string, List<string>> ProcessAssembly(Assembly assembly)
{
int pos = assembly.FullName.IndexOf(", Culture");

string fileName = $"{assembly.FullName.Substring(0, pos)}.json";

Dictionary<string, List<string>> types = new Dictionary<string, List<string>>();
var types = new Dictionary<string, List<string>>();

foreach (var exportedType in assembly.ExportedTypes)
{
List<string> members = new List<string>();
var members = new List<string>();

if (exportedType.IsEnum)
{
Expand Down
4 changes: 1 addition & 3 deletions Microsoft.Toolkit.Uwp.PlatformSpecificAnalyzer/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,7 @@ public static HowToGuard GetGuardForSymbol(ISymbol target)

private static TypePresenceIndicator CheckCollectionForType(Dictionary<string, List<NewMember>> collection, string typeName, ISymbol symbol)
{
List<NewMember> newMembers = null;

if (!collection.TryGetValue(typeName, out newMembers))
if (!collection.TryGetValue(typeName, out var newMembers))
{
return TypePresenceIndicator.NotFound;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ private void AnalyzeExpression(SyntaxNodeAnalysisContext context, ConcurrentDict
}

var line = loc.GetLineSpan().StartLinePosition.Line;

Diagnostic diagnostic = null;

if (reports.TryGetValue(line, out diagnostic) && diagnostic.Location.SourceSpan.Start <= loc.SourceSpan.Start)
if (reports.TryGetValue(line, out var diagnostic) && diagnostic.Location.SourceSpan.Start <= loc.SourceSpan.Start)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ private void AnalyzeExpression(SyntaxNodeAnalysisContext context, ConcurrentDict
}

var line = loc.GetLineSpan().StartLinePosition.Line;

Diagnostic diagnostic = null;

if (reports.TryGetValue(line, out diagnostic) && diagnostic.Location.SourceSpan.Start <= loc.SourceSpan.Start)
if (reports.TryGetValue(line, out var diagnostic) && diagnostic.Location.SourceSpan.Start <= loc.SourceSpan.Start)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.SampleApp.Common;
using Microsoft.Toolkit.Uwp.SampleApp.Controls;
using Microsoft.Toolkit.Uwp.SampleApp.Models;
Expand Down Expand Up @@ -165,7 +164,7 @@ public void RefreshXamlRender()
{
if (CurrentSample != null)
{
var code = string.Empty;
string code;
if (InfoAreaPivot.SelectedItem == PropertiesPivotItem)
{
code = CurrentSample.BindedXamlCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private async Task PreCacheImages(bool loadInMemory = false)
private async Task LoadDataAsync()
{
var source = new PhotosDataSource();
_photoItems = await new PhotosDataSource().GetItemsAsync(true);
_photoItems = await source.GetItemsAsync(true);
}

private async void PreCache_Tapped(object sender, RoutedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private async void ConnectButton_Click(object sender, RoutedEventArgs e)
CallbackUri = CallbackUri.Text
};

var succeeded = LinkedInService.Instance.Initialize(oAuthTokens, LinkedInPermissions.ReadBasicProfile | LinkedInPermissions.WriteShare);
LinkedInService.Instance.Initialize(oAuthTokens, LinkedInPermissions.ReadBasicProfile | LinkedInPermissions.WriteShare);

var loggedIn = await LinkedInService.Instance.LoginAsync();

Expand All @@ -66,7 +66,7 @@ private async void ShareButton_Click(object sender, RoutedEventArgs e)
return;
}

var response = await LinkedInService.Instance.ShareActivityAsync(ShareText.Text);
await LinkedInService.Instance.ShareActivityAsync(ShareText.Text);

var message = new MessageDialog("Share sent to LinkedIn");
await message.ShowAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void Initialize()
tile.VisualElements.Square150x150Logo = Constants.Square150x150Logo;
tile.VisualElements.Wide310x150Logo = Constants.Wide310x150Logo;
tile.VisualElements.Square310x310Logo = Constants.Square310x310Logo;
var dontWait = tile.UpdateAsync(); // Commit changes (no need to await)
_ = tile.UpdateAsync(); // Commit changes (no need to await)

tile.CreateTileUpdater().Update(new TileNotification(_tileContent.GetXml()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void Current_ThemeChanged(object sender, Models.ThemeChangedArgs e)

private async void MarkdownText_ImageClicked(object sender, LinkClickedEventArgs e)
{
if (!Uri.TryCreate(e.Link, UriKind.Absolute, out Uri result))
if (!Uri.IsWellFormedUriString(e.Link, UriKind.Absolute))
{
await new MessageDialog("Masked relative Images needs to be manually handled.").ShowAsync();
}
Expand Down Expand Up @@ -91,7 +91,7 @@ private void SetInitalText(string text)

private async void MarkdownText_LinkClicked(object sender, LinkClickedEventArgs e)
{
if (!Uri.TryCreate(e.Link, UriKind.Absolute, out Uri result))
if (!Uri.IsWellFormedUriString(e.Link, UriKind.Absolute))
{
await new MessageDialog("Masked relative links needs to be manually handled.").ShowAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void Initialize()
tile.VisualElements.Square150x150Logo = Constants.Square150x150Logo;
tile.VisualElements.Wide310x150Logo = Constants.Wide310x150Logo;
tile.VisualElements.Square310x310Logo = Constants.Square310x310Logo;
var dontWait = tile.UpdateAsync(); // Commit changes (no need to await)
_ = tile.UpdateAsync(); // Commit changes (no need to await)

tile.CreateTileUpdater().Update(new TileNotification(_tileContent.GetXml()));
}
Expand Down
11 changes: 5 additions & 6 deletions Microsoft.Toolkit.Uwp.SampleApp/Shell.SamplePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.SampleApp.Pages;
using Microsoft.Toolkit.Uwp.UI.Animations;
using Microsoft.Toolkit.Uwp.UI.Controls;
Expand Down Expand Up @@ -36,11 +35,11 @@ private Sample CurrentSample
set
{
_currentSample = value;
var nop = SetNavViewSelection();
SetNavViewSelection();
}
}

private async Task SetNavViewSelection()
private async void SetNavViewSelection()
vgromfeld marked this conversation as resolved.
Show resolved Hide resolved
{
if (_currentSample != null)
{
Expand All @@ -59,10 +58,10 @@ private async Task SetNavViewSelection()

private void HideSamplePicker()
{
SamplePickerGrid.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
SamplePickerGrid.Visibility = Visibility.Collapsed;
_selectedCategory = null;

var noop = SetNavViewSelection();
SetNavViewSelection();
}

private async void ShowSamplePicker(Sample[] samples = null, bool group = false)
Expand Down Expand Up @@ -323,7 +322,7 @@ private void HideMoreInfo()
animation.Configuration = new DirectConnectedAnimationConfiguration();
}

var t = SamplePickerGridView.TryStartConnectedAnimationAsync(animation, MoreInfoContent.DataContext, "SampleIcon");
_ = SamplePickerGridView.TryStartConnectedAnimationAsync(animation, MoreInfoContent.DataContext, "SampleIcon");
}

MoreInfoContent.DataContext = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ internal void SetParameterForNextFrameNavigation(object parameter)

private void Frame_Navigating(object sender, Windows.UI.Xaml.Navigation.NavigatingCancelEventArgs e)
{
object parameter = null;

object parameter;
if (_nextParameter != null)
{
parameter = _nextParameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ private string GetOperationString()

private string ToExpressionStringInternal()
{
string ret = string.Empty;
string ret;

// Do a recursive depth-first traversal of the node tree to print out the full expression string
switch (GetOperationKind())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,7 @@ internal void PopulateItemPeers()
{
if (item != null)
{
DataGridItemAutomationPeer peer = null;

DataGridItemAutomationPeer peer;
if (oldChildren.ContainsKey(item))
{
peer = oldChildren[item] as DataGridItemAutomationPeer;
Expand Down
Loading