0

I receive such error message "Cannot implicity convert type Test<prevResponse> to Test<futureResponse>", when I remap one layer to another.

My view model:

 public class prevResponse
    {
        [JsonProperty(PropertyName = "HasHouse")]
        [Required]
        public bool HasHouse { get; set; }


        [JsonProperty(PropertyName = "HasCar")]
        [Required]
        public bool HasCar { get; set; }

    }

I Create identical class in other layer as the one above. I remap them:

 public static class propertyRemaper
    {

        public static prevResponse DoMapping(futureResponse input)
        {
                        var ret = new prevResponse
                        {
                            HasHouse = input.HasHouse,
                            HasCar = input.HasCar

                        };
             return ret;
        }
    }

Once I try to use it as a serviceses agent:

   public async Task<Result<futureResponse>> InfoAboutPerson(string name, string surname)
    {
        return await _testData.InfoAboutPerson(name, surname)
        .Then(x => Result.Success(propertyRemaper.DoMapping(x)));
    }

I receive an error. The whole text highlighted after return.

Interface for InfoAboutPerson below:

public interface ITestInterface
{
     Task<Result<futureResponse>> getData(string name, string surname);
 }

Any ideas how to convert it?

  • 1
    Well, your `DoMapping` returns a `prevResponse`. But your `InfoAboutPerson` returns a `Task`. So either change `DoMapping` to convert a `prevRepsponse` to a `futureResponse`, or change the asny function to return a `Task`. – MakePeaceGreatAgain Feb 18 '21 at 09:58
  • private readonly `ITestInterface _testData`. In Interface, instead of getData should be `InfoAboutPerson`. If I change `Task` as well as `Task>` in interface, I receive `Argument 1: cannot convert from Test to Test`. The same as previous, except there is no work `implicit`. And now, it underlines only argument of `DoMapping`. – gromazazzz Feb 18 '21 at 10:16
  • Why do you even call `DoMapping`, when `_testData`already **is** a `Task>`? There´s nothing to map here, as far as I understand your code. – MakePeaceGreatAgain Feb 18 '21 at 10:18
  • But I need to map `prevResponse` to `futureResponse` and do the task with `futureResponse`, and do the task with `futureResponse`, because it's in service agent lawyer, and prevResponse is part of UI. So I need to map `prevResponse` to `futureResponse` do the task `InfoAboutPerson` with `futureResponse` – gromazazzz Feb 18 '21 at 10:24
  • but there is no `prevResponse` involved here - at least I can´t see any- – MakePeaceGreatAgain Feb 18 '21 at 10:27
  • So, if `propertyRemaper` class called before `ITestInterface`, so I do not need to include `DoMapping` into `InfoAboutPerson` task? And the code ` return await _testData.InfoAboutPerson(name, surname) .Then(x => Result.Success(propertyRemaper.DoMapping(x)));` and `InfoAboutPerson` will use `prevResponse` already mapped `futureResponse`? therefore, this could be commented?: `//.Then(x => Result.Success(propertyRemaper.DoMapping(x)));` Because I thought, that in `propertyRemaper.DoMapping(x)` makes a mapping from `prevResponse` to `futureResponse` – gromazazzz Feb 18 '21 at 10:39
  • `DoMapping` maps the other way round, from `future`- to `prevResponse`. However your method should return the former, so there´s no reason to map to `prevResponse` at all. – MakePeaceGreatAgain Feb 18 '21 at 11:10

0 Answers0