.net - How to implement extension method with generic type(T) that returns new T2(T) -
is there way produce generic extension method can take 1 type , convert type passing source object of type constructor of generic/unknown output type?
here's code want create more generic:
<extension()> public function topubliclist(source list(of hashtag)) list(of webserviceapiv1.publicdataclasses.hashtagpublicinfo) homecoming (from ht in source select new webserviceapiv1.publicdataclasses.hashtagpublicinfo(ht)).tolist() end function
basically want effect:
<extension()> public function topubliclist(of t)(source ienumerable(of t), destinationtype type) list(of destinationtype) homecoming (from x t in source select new destinationtype(x)).tolist() end function
have considered using convert.changetype ?
it this:
return (from x t in source select convert.changetype(x, destinationtype)).tolist()
for work, destinationtype must implement interface iconvertible.
.net vb.net generics extension-methods ienumerable
No comments:
Post a Comment