Use new Enum.TryParse(ReadOnlySpan<char>) overload
This commit is contained in:
parent
13fbfe6091
commit
4d1d9f23d5
|
@ -493,11 +493,15 @@ namespace Emby.Dlna
|
|||
: ImageFormat.Jpg;
|
||||
|
||||
var resource = GetType().Namespace + ".Images." + filename.ToLowerInvariant();
|
||||
|
||||
return new ImageStream
|
||||
var stream = _assembly.GetManifestResourceStream(resource);
|
||||
if (stream == null)
|
||||
{
|
||||
Format = format,
|
||||
Stream = _assembly.GetManifestResourceStream(resource)
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ImageStream(stream)
|
||||
{
|
||||
Format = format
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1150,7 +1150,7 @@ namespace Emby.Server.Implementations.Data
|
|||
return null;
|
||||
}
|
||||
|
||||
if (Enum.TryParse(imageType.ToString(), true, out ImageType type))
|
||||
if (Enum.TryParse(imageType, true, out ImageType type))
|
||||
{
|
||||
image.Type = type;
|
||||
}
|
||||
|
@ -1571,7 +1571,6 @@ namespace Emby.Server.Implementations.Data
|
|||
|
||||
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))
|
||||
{
|
||||
item.Audio = audio;
|
||||
|
@ -1610,18 +1609,16 @@ namespace Emby.Server.Implementations.Data
|
|||
{
|
||||
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))
|
||||
{
|
||||
yield return parsedValue;
|
||||
}
|
||||
(fields ??= new List<MetadataField>()).Add(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))
|
||||
{
|
||||
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))
|
||||
{
|
||||
yield return parsedValue;
|
||||
}
|
||||
(types ??= new List<TrailerType>()).Add(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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
return res;
|
||||
|
|
|
@ -8,11 +8,16 @@ namespace MediaBrowser.Controller.Drawing
|
|||
{
|
||||
public class ImageStream : IDisposable
|
||||
{
|
||||
public ImageStream(Stream stream)
|
||||
{
|
||||
Stream = stream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the stream.
|
||||
/// Gets the stream.
|
||||
/// </summary>
|
||||
/// <value>The stream.</value>
|
||||
public Stream? Stream { get; set; }
|
||||
public Stream Stream { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the format.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<CodeAnalysisRuleSet>../jellyfin-tests.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
|
|
Loading…
Reference in New Issue
Block a user