title: webservice generics method and interface in c#?
body: <p>In a Windows Phone application, i consume multiple webservices from different providers. 
  In order to bind the datas in the xaml, i have a class to rule them all. Let's say :</p>
  
  <pre><code>public class Event
  {
    public string Id { get;set;}
    public string Title { get;set;}
    public string Latitude { get;set;}
    public string Longitude { get;set;}
  }
  </code></pre>
  
  <p>When a provider has one webservice, i use a method like :</p>
  
  <pre><code>private List&lt;Event&gt; MigrateCompanyEventToEvent(DataServiceCollection&lt;CompanyEvent&gt; collection)
  {
     var listEvents = new List&lt;Event&gt;();
     foreach(var item in collection)
     {
        var ev = new Event();
        ev.Id = item.itemId.ToString(); //typeof Guid();
        ev.Title = item.companyEventTitle;
        if(item.latitude != null) { ev.Latitude = item.latitude.ToString(); } //typeof double?
        //etc.
        listEvents.Add(ev);
     }
     return listEvents;
  }
  </code></pre>
  
  <p>But...
  I have a provider with a lot of similar webservices. I don't want to write a method for each one so i looked at generics methods. I think i don't understand something.</p>
  
  <p>I have a webservices named KidEvents, ParentalEvents, SingleEvents... all with the same definition. So, I wrote an Interface :</p>
  
  <pre><code>public interface IdataEvents&lt;T&gt;
  {
       Guid entity_id {get;}
       string nameEvent {get;}
       double? latitude {get;}
       double? longitude {get;}
  }
  </code></pre>
  
  <p>And to proceed I wrote :</p>
  
  <pre><code>private List&lt;Event&gt; MigrateGenericOdataToEvent&lt;T&gt;(DataServiceCollection&lt;T&gt; collection) where T:IdataEvents&lt;T&gt;
  {
      var listEvents = new List&lt;Event&gt;();
      foreach(T item in collection)
      {
         var ev = new Event();
         ev.Title = item.nameEvent;
         ev.Id = item.entity_id;
         //etc.
         listEvents.Add(ev);
      }
      return listEvents
  }
  </code></pre>
  
  <p>My problem is, when i use :
       var SingleEvents = MigrateGenericOdataToEvent(collection); //with collection typeof DataServiceCollection</p>
  
  <p>i get an error : </p>
  
  <pre><code>Le type 'm3.ServiceReferenceData.SingleEvents' ne peut pas être utilisé 
  comme paramètre de type 'T' dans le type ou la méthode générique 
  'm3.ViewModels.MainViewModel.MigrateGenericOdataToEvent&lt;T&gt;
  (System.Data.Services.Client.DataServiceCollection&lt;T)'. 
  Il n'y a pas de conversion de référence implicite de 
  'm3.ServiceReferenceData.SingleEvents' en 
  'm3.ViewModels.IdataEvents&lt;m3.ServiceReferenceData.SingleEvents&gt;'.  
  </code></pre>
  
  <p>Sorry, it's in french... It means something like : </p>
  
  <pre><code>The type 'm3.ServiceReferenceData.SingleEvents' can not be used as a paramater 
  of type 'T' in the type or generic method 
  'm3.ViewModels.MainViewModel.MigrateGenericOdataToEvent&lt;T&gt;
  (System.Data.Services.Client.DataServiceCollection&lt;T)'. 
  There is no implicit conversion reference of 'm3.ServiceReferenceData.SingleEvents' 
  in 'm3.ViewModels.IdataEvents&lt;m3.ServiceReferenceData.SingleEvents&gt;'
  </code></pre>
  
  <p>Is it possible to parse datas from SingleEvents, ParentalEvents, KidEvents (all same data model) to one generic Event ? And how can i do that please ?</p>
  
  <p>Thank you very much</p>