C# convert reflection.propertyinfo to Generic.List<>
How do I go about converting a refle开发者_StackOverflowction.propertyinfo[] to a generic.list<>?
One of the List<T>
constructors accepts an IEnumerable<T>
as its argument (i.e., your PropertyInfo array):
var list = new List<PropertyInfo>( propInfoArray );
var list = yourArray.ToList();
Try using .ToList()
http://msdn.microsoft.com/en-us/library/bb342261.aspx
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.
Use the extension method ToList()
available in the System.Linq
namespace:
var myProperties = propertyInfoArray.ToList();
精彩评论