Task List<T> showing Xamarin error

Asked

Viewed 97 times

2

I am creating a Task List<> but the same shows error in 'Tmodel' Error shown: "Tmodel" type or namespace name cannot be found (using a directive or Assembly reference?)

public async Task<List<TModel>>MetodoPostTeste(string RouteCommand, params object[] args)
    {
        var ModelType = typeof(TModel);//take the class
        var ModelTypeName = ModelType.Name;//take the class name
        var ModelWorldLength = "_lib".Length;//takes the size of the class name up to _lib

        //subtracts from the name of the class the _lib, thus being able to specify the route for the post
        var ModelTypeNameRoute = $"{ModelTypeName.Substring(0, ModelTypeName.Length - ModelWorldLength)}";


        _client.BaseAddress = new Uri(_commom.GetBaseUrl());
        var request = new HttpRequestMessage(HttpMethod.Post, $"api/{ModelTypeNameRoute}/{RouteCommand}");

        request.Content = new StringContent(JsonConvert.SerializeObject(""), Encoding.UTF8, "application/json");
        var response = await _client.SendAsync(request);
        var x = response.Content.ReadAsStringAsync();

        List<TModel> ret = JsonConvert.DeserializeObject<List<TModel>>(x.Result);

        return ret;
    }

inserir a descrição da imagem aqui

  • yes, Generic type T is Tmodel

  • When I hover over List<Tmodel> it informs T is Tmodel

  • That’s right, I could use it here

1 answer

2


As I mentioned in the comments, if you intend to use Generics, the method statement is wrong, the generic type specification is missing.

Change signature to the next one you must resolve:

public async Task<List<TModel>>MetodoPostTeste<TModel>(string RouteCommand, params object[] args)
{
    ...
}

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.