C# convert reflection.propertyinfo to Generic.List<>

2.7k views Asked by At

How do I go about converting a reflection.propertyinfo[] to a generic.list<>?

5

There are 5 answers

4
Marc Gravell On BEST ANSWER
var list = yourArray.ToList();
0
Ed Swangren On

One of the List<T> constructors accepts an IEnumerable<T> as its argument (i.e., your PropertyInfo array):

var list = new List<PropertyInfo>( propInfoArray );
2
Nathan Anderson On

Use the extension method ToList() available in the System.Linq namespace:

var myProperties = propertyInfoArray.ToList();
0
Nylo Andy On
0
AudioBubble On

All of the above are correct. But it should also be mentioned that, like List<T> all .net arrays implement IList<T>.

  var IList<PropertyInfo> ilist = reflection.propertyinfo;

Since I know that, almost all my functions accept IList<T> when I need a list-like collection, which I can use with traditional arrays and lists.