There is nothing wonderful if some gibberish written in code cause some compilation error. The method
OfType
applied to a collection of control is a fruit of your fantasy. There is no such thing, as clearly reported by your compiler.
If you wanted to dynamically sort out some objects based on their
runtime types, there are two VB.NET operators,
Is
and
TryCast
; their use should be obvious from the MSDN help pages:
http://msdn.microsoft.com/en-us/library/kb136x1y.aspx[
^],
http://msdn.microsoft.com/en-us/library/zyy863x8.aspx[
^].
As to your
OfType
, there is a generic method
System.Linq.Enumerable.OfType<>
:
http://msdn.microsoft.com/en-us/library/vstudio/bb360913%28v=vs.100%29.aspx[
^].
If you have the version of .NET where it is implemented (please see the comment to the question, thanks to Kornfeld Eliyahu Peter), you can use this method with your collection to
System.IEnumerable
.
These CodeProject articles could be useful:
Extension Methods in .NET[
^],
Extension Methods in VB.NET[
^].
But ultimately, in the implementation of the filtering in such a method you would still need to use the
Is
operator. :-)
—SA