3

I get a custom list from a webservice, I need to convert the custom list in a custom list created on the client.

I get the value of the webservice like this:

List<object> list = ((IList<object>)service.EventosDoDia()).ToList();

Now I need to put the value of the list in my custom list,

List<Evento>

How do I transform my object in this list?

Class Eventos

public class Eventos
{
    public string id { get; set; }
    public string logo { get; set; }
    public string data { get; set; }
    public string texto { get; set; }
    public string comentarios { get; set; }
}

see the print debug, look at the values ​​that I have in my list http://i50.tinypic.com/14mt1ti.png

5
  • what is that object looks like? Commented Feb 28, 2013 at 12:27
  • why not stay with list<object>? i don't think there is a need of type-exactness when displaying items of a list.... also Http://www.whathaveyoutried.com Commented Feb 28, 2013 at 12:27
  • @andy guess it's spanish. Evento should be a custom class, while EventosDoDia() should return a IQueryable of Eventos who fulfil the condition they happened this day Commented Feb 28, 2013 at 12:29
  • Eventos is custom class, EventosDoDia() is a return webservice Commented Feb 28, 2013 at 12:33
  • I don't agree that this question should have been closed. The one marked as duplicate was not answered and is closed as "Not a real question". It's obvious that English isn't this persons first language so give him a break. Commented Feb 28, 2013 at 17:58

2 Answers 2

4
using System.Linq;

var eventList = list.Cast<Evento>().ToList();
Sign up to request clarification or add additional context in comments.

2 Comments

I tried but the error debugging and saw that que eventList = null
ToList won't ever return null. There ought to be a mistake on your side. If your list is null, you will get an ArgumentNullException.
0

looks like

var list = service.EventosDoDia.ToList();

var event = new List<Evento>();
list.ForEech(c => 
               {
                 event.Add(new Evento()
                           {
                             id = c.SomeIdFromService,
                             logo = c.SomeForLogoService
                             //TOPO: Some Properties
                           };
               });

6 Comments

Looks like that's what you're talking about, most did not understand that part of (c.SomeIdFromService and c.SomeForLogoService).
oh yes.. it just an example from the properties of service.EventosDoDia, you can just replace that from the actual proprieties you have :)
mhmm.. i updated my answer, if you really have a List of EventosDoDia you can see the properties of the EventosDoDia
EventosDoDia is the return from webservice
Cannot implicitly convert type System.Collections.Generic.List<iClubs.ws.Eventos>' to System.Collections.Generic.List<iClubs.Eventos>'
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.