Removed nesting levels through block-scoped `using` statement (#10025)

Co-authored-by: John Doe <john@doe>
Co-authored-by: Lehonti Ramos <lehonti@ramos>
pull/10217/head
Lehonti Ramos 9 months ago committed by GitHub
parent c79c59a32b
commit bc959270b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
@ -59,22 +59,18 @@ public class MigrateMusicBrainzTimeout : IMigrationRoutine
private OldMusicBrainzConfiguration? ReadOld(string path)
{
using (var xmlReader = XmlReader.Create(path))
{
using var xmlReader = XmlReader.Create(path);
var serverConfigSerializer = new XmlSerializer(typeof(OldMusicBrainzConfiguration), new XmlRootAttribute("PluginConfiguration"));
return serverConfigSerializer.Deserialize(xmlReader) as OldMusicBrainzConfiguration;
}
}
private void WriteNew(string path, PluginConfiguration newPluginConfiguration)
{
var pluginConfigurationSerializer = new XmlSerializer(typeof(PluginConfiguration), new XmlRootAttribute("PluginConfiguration"));
var xmlWriterSettings = new XmlWriterSettings { Indent = true };
using (var xmlWriter = XmlWriter.Create(path, xmlWriterSettings))
{
using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
pluginConfigurationSerializer.Serialize(xmlWriter, newPluginConfiguration);
}
}
#pragma warning disable
public sealed class OldMusicBrainzConfiguration

@ -43,11 +43,9 @@ public class MigrateNetworkConfiguration : IMigrationRoutine
try
{
using (var xmlReader = XmlReader.Create(path))
{
using var xmlReader = XmlReader.Create(path);
oldNetworkConfiguration = (OldNetworkConfiguration?)oldNetworkConfigSerializer.Deserialize(xmlReader);
}
}
catch (InvalidOperationException ex)
{
_logger.LogError(ex, "Migrate NetworkConfiguration deserialize Invalid Operation error");
@ -97,12 +95,10 @@ public class MigrateNetworkConfiguration : IMigrationRoutine
var networkConfigSerializer = new XmlSerializer(typeof(NetworkConfiguration));
var xmlWriterSettings = new XmlWriterSettings { Indent = true };
using (var xmlWriter = XmlWriter.Create(path, xmlWriterSettings))
{
using var xmlWriter = XmlWriter.Create(path, xmlWriterSettings);
networkConfigSerializer.Serialize(xmlWriter, networkConfiguration);
}
}
}
#pragma warning disable
public sealed class OldNetworkConfiguration

@ -489,11 +489,9 @@ public class SkiaEncoder : IImageEncoder
Directory.CreateDirectory(directory);
using (var outputStream = new SKFileWStream(outputPath))
{
using (var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels()))
{
using var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels());
pixmap.Encode(outputStream, skiaOutputFormat, quality);
}
}
return outputPath;
}

@ -111,11 +111,9 @@ public sealed class ImageProcessor : IImageProcessor, IDisposable
public async Task ProcessImage(ImageProcessingOptions options, Stream toStream)
{
var file = await ProcessImage(options).ConfigureAwait(false);
using (var fileStream = AsyncFile.OpenRead(file.Path))
{
using var fileStream = AsyncFile.OpenRead(file.Path);
await fileStream.CopyToAsync(toStream).ConfigureAwait(false);
}
}
/// <inheritdoc />
public IReadOnlyCollection<ImageFormat> GetSupportedImageOutputFormats()

@ -26,11 +26,9 @@ namespace Jellyfin.Extensions
/// <returns>All lines in the stream.</returns>
public static string[] ReadAllLines(this Stream stream, Encoding encoding)
{
using (StreamReader reader = new StreamReader(stream, encoding))
{
using StreamReader reader = new StreamReader(stream, encoding);
return ReadAllLines(reader).ToArray();
}
}
/// <summary>
/// Reads all lines in the <see cref="TextReader" />.

@ -12,8 +12,8 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
[Fact]
public void Parse_Valid_Success()
{
using (var stream = File.OpenRead("Test Data/example.ass"))
{
using var stream = File.OpenRead("Test Data/example.ass");
var parsed = new SubtitleEditParser(new NullLogger<SubtitleEditParser>()).Parse(stream, "ass");
Assert.Single(parsed.TrackEvents);
var trackEvent = parsed.TrackEvents[0];
@ -24,5 +24,4 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
Assert.Equal("{\\pos(400,570)}Like an Angel with pity on nobody" + Environment.NewLine + "The second line in subtitle", trackEvent.Text);
}
}
}
}

@ -12,8 +12,8 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
[Fact]
public void Parse_Valid_Success()
{
using (var stream = File.OpenRead("Test Data/example.srt"))
{
using var stream = File.OpenRead("Test Data/example.srt");
var parsed = new SubtitleEditParser(new NullLogger<SubtitleEditParser>()).Parse(stream, "srt");
Assert.Equal(2, parsed.TrackEvents.Count);
@ -29,13 +29,12 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
Assert.Equal(TimeSpan.Parse("00:02:22.501", CultureInfo.InvariantCulture).Ticks, trackEvent2.EndPositionTicks);
Assert.Equal("Very good, Lieutenant.", trackEvent2.Text);
}
}
[Fact]
public void Parse_EmptyNewlineBetweenText_Success()
{
using (var stream = File.OpenRead("Test Data/example2.srt"))
{
using var stream = File.OpenRead("Test Data/example2.srt");
var parsed = new SubtitleEditParser(new NullLogger<SubtitleEditParser>()).Parse(stream, "srt");
Assert.Equal(2, parsed.TrackEvents.Count);
@ -52,5 +51,4 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
Assert.Equal("este lugar se convertirá" + Environment.NewLine + Environment.NewLine + "en un maldito zoológico.", trackEvent2.Text);
}
}
}
}

@ -18,8 +18,8 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
[MemberData(nameof(Parse_MultipleDialogues_TestData))]
public void Parse_MultipleDialogues_Success(string ssa, IReadOnlyList<SubtitleTrackEvent> expectedSubtitleTrackEvents)
{
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(ssa)))
{
using Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(ssa));
SubtitleTrackInfo subtitleTrackInfo = _parser.Parse(stream, "ssa");
Assert.Equal(expectedSubtitleTrackEvents.Count, subtitleTrackInfo.TrackEvents.Count);
@ -35,7 +35,6 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
Assert.Equal(expected.EndPositionTicks, actual.EndPositionTicks);
}
}
}
public static TheoryData<string, IReadOnlyList<SubtitleTrackEvent>> Parse_MultipleDialogues_TestData()
{
@ -73,8 +72,8 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
[Fact]
public void Parse_Valid_Success()
{
using (var stream = File.OpenRead("Test Data/example.ssa"))
{
using var stream = File.OpenRead("Test Data/example.ssa");
var parsed = _parser.Parse(stream, "ssa");
Assert.Single(parsed.TrackEvents);
var trackEvent = parsed.TrackEvents[0];
@ -85,5 +84,4 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
Assert.Equal("{\\pos(400,570)}Like an angel with pity on nobody", trackEvent.Text);
}
}
}
}

@ -488,8 +488,9 @@ namespace Jellyfin.Model.Tests
private static async ValueTask<T> TestData<T>(string name)
{
var path = Path.Join("Test Data", typeof(T).Name + "-" + name + ".json");
using (var stream = File.OpenRead(path))
{
using var stream = File.OpenRead(path);
var value = await JsonSerializer.DeserializeAsync<T>(stream, JsonDefaults.Options);
if (value is not null)
{
@ -498,7 +499,6 @@ namespace Jellyfin.Model.Tests
throw new SerializationException("Invalid test data: " + name);
}
}
private StreamBuilder GetStreamBuilder()
{

Loading…
Cancel
Save