Generics question
-
Hi, I got a problem that I would like to return a generic object in a non-generic object, what can I do? I searched a lot of page but it's talking about how to use or implement a generic class, but if I want to implement a normal class and return a generic object according parameter, what can I do? e.g. class DaoFactory { Dao<T, IdT> GetDao(Type t) { //something like this. //how to implement? } } Thanks Jr. P calendarw
-
Hi, I got a problem that I would like to return a generic object in a non-generic object, what can I do? I searched a lot of page but it's talking about how to use or implement a generic class, but if I want to implement a normal class and return a generic object according parameter, what can I do? e.g. class DaoFactory { Dao<T, IdT> GetDao(Type t) { //something like this. //how to implement? } } Thanks Jr. P calendarw
How about this one? /// /// Convert an ArrayList from a derived type to the base type /// /// Derived type /// Base type /// The ArrayList /// An ArrayList containing elements converted to the base type public static List Transform(List list) where S : D { List lst = new List(); foreach (S element in list) lst.Add(element); return lst; } I will use Google before asking dumb questions
-
How about this one? /// /// Convert an ArrayList from a derived type to the base type /// /// Derived type /// Base type /// The ArrayList /// An ArrayList containing elements converted to the base type public static List Transform(List list) where S : D { List lst = new List(); foreach (S element in list) lst.Add(element); return lst; } I will use Google before asking dumb questions
Thank you. I changed to this: public static List<D> Transform<D>(System.Collections.IList list) { List<D> lst = new List<D>(); foreach (D element in list) lst.Add(element); return lst; } Actually, I tried to search using google but I don't know what keyword should be used for this case.
-
Thank you. I changed to this: public static List<D> Transform<D>(System.Collections.IList list) { List<D> lst = new List<D>(); foreach (D element in list) lst.Add(element); return lst; } Actually, I tried to search using google but I don't know what keyword should be used for this case.
How about [this] Hope it helps.
I will use Google before asking dumb questions
-
How about [this] Hope it helps.
I will use Google before asking dumb questions
Thank you for your information. And I would like to implement something like this: public interface IReadOnlyDao { object GetById(object id); IList GetAll(); } public interface IReadOnlyDao<T, IdT> : IReadOnlyDao { T GetById(IdT id); IList<T, IdT> GetAll(); } But when I implementing the GetAll(), I got a problem that two method are same name and same parameter, is it possible to implement? or I am required to use convert the list using previous discuss method. Thank you very much.
-
Thank you for your information. And I would like to implement something like this: public interface IReadOnlyDao { object GetById(object id); IList GetAll(); } public interface IReadOnlyDao<T, IdT> : IReadOnlyDao { T GetById(IdT id); IList<T, IdT> GetAll(); } But when I implementing the GetAll(), I got a problem that two method are same name and same parameter, is it possible to implement? or I am required to use convert the list using previous discuss method. Thank you very much.
I think it will be better to use the converter. My opinion
I will use Google before asking dumb questions
-
I think it will be better to use the converter. My opinion
I will use Google before asking dumb questions