I have a C# project targetting .NET 9.0 in which I'm wrapping yt-dlp (CLI video downloader) so you can use it directly in .NET or PowerShell. Unfortunately, I have a switch statement that needs to select between enum values. You can get the project from Chasing-many-issues. On lines 88, 93, and 98 of Goodies/PowerShell/WillPittenger.Goodies.PowerShell.YtDlpWrapper/GetInfoFromYtDlp.cs, Visual Studio 2022 Community reports it can't find an enum value, CS0246. But when I go to the declaration of the type, ItemTypes
(describes what an JSON object returned from yt-dlp is), it declares all three values that the IDE complains about. The IDE did see the enum type itself along with other types in the enum's namespace. So why doesn't it find entries in the enum type? I tried recompiling the entire solution and restarting Visual Studio. Neither helped.
Any suggestions?
The declaration of ItemTypes
:
namespace WillPittenger.Goodies.YtDlpWrapper;
public class YtDlpWrapper
{
public enum ItemTypes
{
chan,
playList,
vid,
}
}
The switch statement
namespace WillPittenger.Goodies.PowerShell.YtDlpWrapper;
[System.Management.Automation.OutputType(typeof(Goodies.YtDlpWrapper.Chan), typeof(Goodies.YtDlpWrapper.Vid), typeof(Goodies.YtDlpWrapper.PlayList))]
[System.Management.Automation.Alias("gvi")]
[System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.Get, "InfoFromYtDlp")]
public class GetInfoFromYtDlp : BaseCmdLet
{
⋮
switch(joDataToWrite.Values[Goodies.YtDlpWrapper.YtDlpWrapper.KnownYtDlpFields.field_ItemType.strName].val.objVal)
{
case Goodies.YtDlpWrapper.YtDlpWrapper.ItemTypes.chan.ToString():
WriteObject(new Goodies.YtDlpWrapper.Chan(joDataToWrite));
break;
case Goodies.YtDlpWrapper.YtDlpWrapper.ItemTypes.playList.ToString():
WriteObject(new Goodies.YtDlpWrapper.PlayList(joDataToWrite));
break;
case Goodies.YtDlpWrapper.YtDlpWrapper.ItemTypes.vid.ToString():
WriteObject(new Goodies.YtDlpWrapper.Vid(joDataToWrite));
break;
default:
throw new System.InvalidOperationException($"Unable to interpret entry sent back from yt-dlp.");
}
⋮
}