Reputation: 1172
How to call C# overridden methods with exact same named arguments?
Example
public static Task<CreateImageSummaryModel> CreateImagesFromDataAsync(this ITrainingApi operations, Guid projectId, IEnumerable<Stream> imageData, IList<Guid> tagIds = null, CancellationToken cancellationToken = default(CancellationToken));
public static Task<CreateImageSummaryModel> CreateImagesFromDataAsync(this ITrainingApi operations, Guid projectId, Stream imageData, IList<string> tagIds = null, CancellationToken cancellationToken = default(CancellationToken));
Same method name and argument names, but args have different signatures.
Now trying to call first method
let uploadStreams (tag: string) (streams: Stream seq) (projectId: Guid) (trainingApi: TrainingApi) =
let tag = trainingApi.CreateTag(projectId, tag)
let tags = new List<_>([tag.Id])
let streams = streams :> IEnumerable<Stream>
trainingApi.CreateImagesFromDataAsync(projectId, imageData = streams, tagIds = tags)
This gives compilation error
Severity Code Description Project File Line Suppression State
Error FS0001 The type 'IEnumerable<Stream>' is not compatible with the type 'Stream'
Severity Code Description Project File Line Suppression State
Error FS0193 Type constraint mismatch. The type 'IEnumerable<Stream>' is not compatible with type 'Stream'
Severity Code Description Project File Line Suppression State
Error FS0001 The type 'List<Guid>' is not compatible with the type 'IList<string>' VisionAPI
Usually when I deal with overridden methods in F# I just use explicit argument names such as
let x = cls.someOverriddenMethod(arg1 = 1)
But in this case this not works.
How should I proceed in this case ?
Thanks
Upvotes: 3
Views: 110
Reputation: 1172
Happens these definitions were taken from CustomVision API 1.0
public static Task<CreateImageSummaryModel> CreateImagesFromDataAsync(this ITrainingApi operations, Guid projectId, IEnumerable<Stream> imageData, IList<Guid> tagIds = null, CancellationToken cancellationToken = default(CancellationToken));
public static Task<CreateImageSummaryModel> CreateImagesFromDataAsync(this ITrainingApi operations, Guid projectId, Stream imageData, IList<string> tagIds = null, CancellationToken cancellationToken = default(CancellationToken));
And my F# app use version API 1.2 in which first method is no longer exists (which is strange)
At least mystery solved.
Upvotes: 0
Reputation: 6510
I think the issue is that imageData
is not an optional parameter, but you're passing it like it is one. Just pass streams
directly instead of using imageData = streams
. Here's a minimal working example that compiles for me:
open System
open System.IO
type MyType () =
static member A(a: string, b: Guid, c: Stream seq, ?d: Guid list) = ()
static member A(a: string, b: Guid, c: Stream, ?d: Guid list) = ()
let f (streams: Stream seq) guids =
MyType.A("", Guid.Empty, streams, d = guids)
MyType.A("", Guid.Empty, streams |> Seq.head, d = guids)
Upvotes: 3