Skip to content

Commit

Permalink
Replace manual Lazy<T> implementation with Fody
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Aug 20, 2023
1 parent 3e283ee commit c5cba26
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
9 changes: 4 additions & 5 deletions YoutubeDownloader.Core/Downloading/VideoDownloadOption.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Lazy;
using YoutubeDownloader.Core.Utils;
using YoutubeDownloader.Core.Utils.Extensions;
using YoutubeExplode.Videos.Streams;
Expand All @@ -12,11 +13,9 @@ public partial record VideoDownloadOption(
bool IsAudioOnly,
IReadOnlyList<IStreamInfo> StreamInfos)
{
private readonly Lazy<VideoQuality?> _videoQualityLazy = new(() =>
StreamInfos.OfType<IVideoStreamInfo>().MaxBy(s => s.VideoQuality)?.VideoQuality
);

public VideoQuality? VideoQuality => _videoQualityLazy.Value;
[Lazy]
public VideoQuality? VideoQuality =>
StreamInfos.OfType<IVideoStreamInfo>().MaxBy(s => s.VideoQuality)?.VideoQuality;
}

public partial record VideoDownloadOption
Expand Down
3 changes: 3 additions & 0 deletions YoutubeDownloader.Core/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Lazy />
</Weavers>
26 changes: 26 additions & 0 deletions YoutubeDownloader.Core/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Lazy" minOccurs="0" maxOccurs="1" type="xs:anyType" />
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
1 change: 1 addition & 0 deletions YoutubeDownloader.Core/YoutubeDownloader.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ItemGroup>
<PackageReference Include="Gress" Version="2.1.1" />
<PackageReference Include="JsonExtensions" Version="1.2.0" />
<PackageReference Include="Lazy.Fody" Version="1.11.0" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="YoutubeExplode" Version="6.3.2" />
<PackageReference Include="YoutubeExplode.Converter" Version="6.3.2" />
Expand Down

0 comments on commit c5cba26

Please sign in to comment.