C
C#•5mo ago
Davaaron

Why do i need to pass in the generics here?

Hey, I have this code
using GitManager.Domain.Models;
using GitManager.GitCLI.Commands.Parsing;

namespace GitManager.GitCLI.Commands
{
public record GitPullBranchCommandInput : IGitCommandInput
{
public string LocalPath { get; }
/// <summary>
/// When not specified, the current local checked out branch will be pulled.
/// </summary>
public string? Branch { get; }

public GitPullBranchCommandInput(string localPath, string? branch = null)
{
LocalPath = localPath;
Branch = branch;
}
}
public class GitPullBranchCommand : IGitCommand<string, GitPullBranchCommandInput>
{
private readonly IGitCommandStrategy _gitCommandStrategy;

public GitPullBranchCommand(IGitCommandStrategy gitCommandStrategy)
{
_gitCommandStrategy = gitCommandStrategy;
}

public async Task<string> ExecuteAsync(GitPullBranchCommandInput input)
{
//var command = "branch --list --all";
var command = "pull";
var result = await _gitCommandStrategy.ExecuteAsync(command, input.LocalPath);

return result;
}
}
}
using GitManager.Domain.Models;
using GitManager.GitCLI.Commands.Parsing;

namespace GitManager.GitCLI.Commands
{
public record GitPullBranchCommandInput : IGitCommandInput
{
public string LocalPath { get; }
/// <summary>
/// When not specified, the current local checked out branch will be pulled.
/// </summary>
public string? Branch { get; }

public GitPullBranchCommandInput(string localPath, string? branch = null)
{
LocalPath = localPath;
Branch = branch;
}
}
public class GitPullBranchCommand : IGitCommand<string, GitPullBranchCommandInput>
{
private readonly IGitCommandStrategy _gitCommandStrategy;

public GitPullBranchCommand(IGitCommandStrategy gitCommandStrategy)
{
_gitCommandStrategy = gitCommandStrategy;
}

public async Task<string> ExecuteAsync(GitPullBranchCommandInput input)
{
//var command = "branch --list --all";
var command = "pull";
var result = await _gitCommandStrategy.ExecuteAsync(command, input.LocalPath);

return result;
}
}
}
and i want to use to probably like this
Branch branch = await gitHandler.ExecuteAsync(new GitPullBranchCommandInput(""));
Branch branch = await gitHandler.ExecuteAsync(new GitPullBranchCommandInput(""));
But it says i cannot the determine the types... why not?! they are clearly given..
5 Replies
reflectronic
reflectronic•5mo ago
you will have to give the exact error
Davaaron
DavaaronOP•5mo ago
The error message is
Error (active) CS0411 The type arguments for method 'IGitCommandHandler.ExecuteAsync<TOutput, TInput>(TInput)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Error (active) CS0411 The type arguments for method 'IGitCommandHandler.ExecuteAsync<TOutput, TInput>(TInput)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
canton7
canton7•5mo ago
IGitCommandHandler.ExecuteAsync is a method you wrote? How is it supposed to infer TOutput? It doesn't appear as one of the parameters, so it can't use the type of a parameter to figure it out
Davaaron
DavaaronOP•5mo ago
Sorry for the late response. Yes, it is. Well I thought it could infer it because I write Author author = ..., of course it cannot when I write var author = .... My final design idea was to have a lot of git command classes that takes a specific input parameter and produces an output, so i could use it like Author author = await gitCommandHandler.ExecuteAsync(new GitGetAuthorCommandInput()) or await gitCommandHandler.ExecuteAsync(new GitSetAuthorCommandInput{ Name = "ChangedName" }); If i cannot get this done I already have some ideas in mind 😄 transition to a big static class "GitCommands" that has all those methods... or maybe i will create a lot of domain objects (Repository, Branch, Commit, Tag, etc.) that has the logic built-in (CreateBranch, AddLocalChanges, ResetCommit, etc.)
canton7
canton7•5mo ago
Generic arguments aren't inferred from the target type I'm afraid
Want results from more Discord servers?
Add your server