Hello Guys Please Help Me To Fix This…
This Is My Models :
public class Result1
{
public string Price { get; set; }
public string Id { get; set; }
}
public class Result2
{
public string firstName { get; set; }
public string lastName { get; set; }
public string Id { get; set; }
}
public class JsonResult1
{
public List<Product> ProductLists { get; set; }
}
public class JsonResult2
{
public List<User> UserLists { get; set; }
}
And This is My First And Second Methods
public async Task<List<Result1>> GetFirstMethod(string id, string a)
{
var info = JsonConvert.DeserializeObject<JsonResult1>(a);
var mylist = new List<Result1>();
foreach (var item in info.ProductLists)
{
mylist.Add(new Result1()
{
Price = item.Price,
Id = item.ID
});
}
return mylist;
}
public async Task<List<Result2>> GetSecondMethod(string id, string a)
{
var info = JsonConvert.DeserializeObject<JsonResult2>(a);
var mylist = new List<Result2>();
foreach (var item in info.UserLists)
{
mylist.Add(new Result2()
{
firstName = item.FirstName,
lastName = item.LastName,
Id = item.ID
});
}
return mylist;
}
//And the third method and the fourth method and...
Each method has different models…
How to make a generic method for All the above methods??
The main problem is in the mapping part inside the list…
Is it even possible to do something like this? Or not
thank you
New contributor
Ya YA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.