Use new Enum.TryParse(ReadOnlySpan<char>) overload

pull/6595/head
Bond_009 4 years ago
parent 13fbfe6091
commit 4d1d9f23d5

@ -493,11 +493,15 @@ namespace Emby.Dlna
: ImageFormat.Jpg; : ImageFormat.Jpg;
var resource = GetType().Namespace + ".Images." + filename.ToLowerInvariant(); var resource = GetType().Namespace + ".Images." + filename.ToLowerInvariant();
var stream = _assembly.GetManifestResourceStream(resource);
if (stream == null)
{
return null;
}
return new ImageStream return new ImageStream(stream)
{ {
Format = format, Format = format
Stream = _assembly.GetManifestResourceStream(resource)
}; };
} }

@ -1150,7 +1150,7 @@ namespace Emby.Server.Implementations.Data
return null; return null;
} }
if (Enum.TryParse(imageType.ToString(), true, out ImageType type)) if (Enum.TryParse(imageType, true, out ImageType type))
{ {
image.Type = type; image.Type = type;
} }
@ -1571,7 +1571,6 @@ namespace Emby.Server.Implementations.Data
if (reader.TryGetString(index++, out var audioString)) if (reader.TryGetString(index++, out var audioString))
{ {
// TODO Span overload coming in the future https://github.com/dotnet/runtime/issues/1916
if (Enum.TryParse(audioString, true, out ProgramAudio audio)) if (Enum.TryParse(audioString, true, out ProgramAudio audio))
{ {
item.Audio = audio; item.Audio = audio;
@ -1610,18 +1609,16 @@ namespace Emby.Server.Implementations.Data
{ {
if (reader.TryGetString(index++, out var lockedFields)) if (reader.TryGetString(index++, out var lockedFields))
{ {
IEnumerable<MetadataField> GetLockedFields(string s) List<MetadataField> fields = null;
foreach (var i in lockedFields.Split('|'))
{ {
foreach (var i in s.Split('|', StringSplitOptions.RemoveEmptyEntries)) if (Enum.TryParse(i, true, out MetadataField parsedValue))
{ {
if (Enum.TryParse(i, true, out MetadataField parsedValue)) (fields ??= new List<MetadataField>()).Add(parsedValue);
{
yield return parsedValue;
}
} }
} }
item.LockedFields = GetLockedFields(lockedFields).ToArray(); item.LockedFields = fields?.ToArray() ?? Array.Empty<MetadataField>();
} }
} }
@ -1647,18 +1644,16 @@ namespace Emby.Server.Implementations.Data
{ {
if (reader.TryGetString(index, out var trailerTypes)) if (reader.TryGetString(index, out var trailerTypes))
{ {
IEnumerable<TrailerType> GetTrailerTypes(string s) List<TrailerType> types = null;
foreach (var i in trailerTypes.Split('|'))
{ {
foreach (var i in s.Split('|', StringSplitOptions.RemoveEmptyEntries)) if (Enum.TryParse(i, true, out TrailerType parsedValue))
{ {
if (Enum.TryParse(i, true, out TrailerType parsedValue)) (types ??= new List<TrailerType>()).Add(parsedValue);
{
yield return parsedValue;
}
} }
} }
trailer.TrailerTypes = GetTrailerTypes(trailerTypes).ToArray(); trailer.TrailerTypes = types.ToArray() ?? Array.Empty<TrailerType>();
} }
} }

@ -1250,10 +1250,8 @@ namespace Emby.Server.Implementations.Library
private CollectionTypeOptions? GetCollectionType(string path) private CollectionTypeOptions? GetCollectionType(string path)
{ {
var files = _fileSystem.GetFilePaths(path, new[] { ".collection" }, true, false); var files = _fileSystem.GetFilePaths(path, new[] { ".collection" }, true, false);
foreach (var file in files) foreach (ReadOnlySpan<char> file in files)
{ {
// TODO: @bond use a ReadOnlySpan<char> here when Enum.TryParse supports it
// https://github.com/dotnet/runtime/issues/20008
if (Enum.TryParse<CollectionTypeOptions>(Path.GetFileNameWithoutExtension(file), true, out var res)) if (Enum.TryParse<CollectionTypeOptions>(Path.GetFileNameWithoutExtension(file), true, out var res))
{ {
return res; return res;

@ -8,11 +8,16 @@ namespace MediaBrowser.Controller.Drawing
{ {
public class ImageStream : IDisposable public class ImageStream : IDisposable
{ {
public ImageStream(Stream stream)
{
Stream = stream;
}
/// <summary> /// <summary>
/// Gets or sets the stream. /// Gets the stream.
/// </summary> /// </summary>
/// <value>The stream.</value> /// <value>The stream.</value>
public Stream? Stream { get; set; } public Stream Stream { get; }
/// <summary> /// <summary>
/// Gets or sets the format. /// Gets or sets the format.

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<CodeAnalysisRuleSet>../jellyfin-tests.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>../jellyfin-tests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>

Loading…
Cancel
Save