开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜