Excellent thanks very much
- RH
[ComDefaultInterface(typeof(IEnumerable))]
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WinSCP" Version="5.21.8" />
</ItemGroup>
</Project>
using WinSCP;
namespace ConsoleApp1;
internal class Program
{
static void Main()
{
Session session = new();
// Information diagnostic on next line
foreach (RemoteFileInfo _ in session.ListDirectory("").Files)
{
}
}
}
dotnet/interopcollections
explicitly implement GetEnumerator
on the generic IEnumerable<T>
and publicly/implicitly implement the nongeneric version:
IEnumerator<TransferEventArgs> IEnumerable<TransferEventArgs>.GetEnumerator()
{
return _helper.GetEnumerator();
}
public IEnumerator GetEnumerator()
{
return _helper.GetEnumerator();
}
foreach (TransferEventArgs upload in synchronizationResult.Uploads)
{
}
IDE0220 'foreach' statement implicitly converts 'object' to 'WinSCP.TransferEventArgs'. Add an explicit cast to make intent clearer, as it may fail at runtime
foreach
using the nongeneric GetEnumerator
and iterating the items as object type.
GetEnumerator
and explicitly implemented the nongeneric version, e.g.
diff --git a/dotnet/interopcollections/TransferEventArgsCollection.cs b/dotnet/interopcollections/TransferEventArgsCollection.cs
index 5d5a4dc4c..a8e435a51 100644
--- a/dotnet/interopcollections/TransferEventArgsCollection.cs
+++ b/dotnet/interopcollections/TransferEventArgsCollection.cs
@@ -66,7 +66,7 @@ namespace WinSCP
#region IEnumerable<SessionRemoteException> Members
- IEnumerator<TransferEventArgs> IEnumerable<TransferEventArgs>.GetEnumerator()
+ public IEnumerator<TransferEventArgs> GetEnumerator()
{
return _helper.GetEnumerator();
}
@@ -75,7 +75,7 @@ namespace WinSCP
#region IEnumerable Members
- public IEnumerator GetEnumerator()
+ IEnumerator IEnumerable.GetEnumerator()
{
return _helper.GetEnumerator();
}