Entradas

Mostrando las entradas etiquetadas como Ilist

Caso practico por que usar una Interfaz

a causa del post anterior Cannot serialize member 'Objects' of type 'System.Collections.Generic.IList`1.... varios me preguntaron por que usar Ilist y no List directamente. Bueno aquí un pequeño y muy cotidiano ejemplo, que sirve para entender las gracias de las interfaces. Supongamos que tenemos 2 clases una llamada "auto" y otra "camion" y ambas tienen un numero de patente. y en algún reporte o pantalla solo tenemos que listar solo la Patente seria de la siguiente forma. public interface IPatentable { String Patente { set; get; } } public class Auto:IPatentable { public String Patente { set; get; } public Int32 CantidadDePuertas { set; get; } } public class Camion:IPatentable { public String Patente { set; get; } public Int64 Peso { set; get; } } y después en un objeto Dao , para rescatar los datos desde algún origen, ya sea base de datos, webservice, etc.: public IList<IPatentable> GetPAtentes() { var auto1 = new Aut...

Cannot serialize member 'Objects' of type 'System.Collections.Generic.IList`1....

Hoy me he encontrado con este problema, trantado de serializar un objeto a xml, por alguna razón no se pueden serializar objetos que contengan atributos Ilist. La foma de la que estaba trantando es la siguiente [Serializable] public class Person{ public Person (){ Address = new list<Address>(); } public String Name{set;get;} public IList<Address> Address {set;get;} public void ToXml() { var serializer = new XmlSerializer(typeof(Voucher)); var writer = new XmlTextWriter(Console.Out); serializer.Serialize(writer, this); } } y obviamente ejecuto esto desde un test unitario como el que sigue: [Test] public void TestForPersonToXml() { var person = new person(); Person.NAme = "victor Hugo Saavedra"; var Add = new Address(); add.street = "Alameda"; add.number = "1234"; Person.Address.add(add) person.ToXml(); } Pero al momento de ejecutar el test me da el...