c# - DataTable to List<T> conversion -
Is there a better way than the following?
Specifically, I want to change the Activator
with something else.
Public Stable List & lt; T & gt; ToList & lt; T & gt; (Datatelle dt) {type type = typef (t); & Lt; T & gt; List = new list & lt; T & gt; (); Foreach (DataRow dr in dt.ows) {object [args = new object [1]; Argus [0] = Dr.; List Add (T) Catalyst Create Science (types, args)); } Return list; } The first thing I want to say is that you probably do not want anyone List There are obstacles, an IEnumerable is enough, even if you need a list, then it's trivial to convert an IEnumerable to a list.
Keeping this in mind, this code is a good general way to accomplish this:
Public Fixed IEnumerable & lt; T & gt; Genius & lt; T & gt; (Datatelle DT, Funk & lt; Detaar, T & T; translator) {foreach (Detroe Dr. in dt.Rows) {yield returns translator (Dr.); }}
Hope you can see how this is reusable. You only need to provide a function that is how to convert an individual detection to T Knows. This function may use the perhaps activator, but this is not the case for it, it can only use a generic manufacturer and set some properties.
Comments
Post a Comment