Training
Module
Perform operations on arrays using helper methods in C# - Training
Use C# helper methods to perform reverse, resize, split and join operations on arrays.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The following example shows how LINQ can be used with reflection to retrieve specific metadata about methods that match a specified search criterion. In this case, the query will find the names of all the methods in the assembly that return enumerable types such as arrays.
Imports System.Linq
Imports System.Reflection
Module Module1
Sub Main()
Dim asmbly As Assembly =
Assembly.Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken= b77a5c561934e089")
Dim pubTypesQuery = From type In asmbly.GetTypes()
Where type.IsPublic
From method In type.GetMethods()
Where method.ReturnType.IsArray = True
Let name = method.ToString()
Let typeName = type.ToString()
Group name By typeName Into methodNames = Group
Console.WriteLine("Getting ready to iterate")
For Each item In pubTypesQuery
Console.WriteLine(item.methodNames)
For Each type In item.methodNames
Console.WriteLine(" " & type)
Next
Next
Console.WriteLine("Press any key to exit... ")
Console.ReadKey()
End Sub
End Module
The example uses the Assembly.GetTypes method to return an array of types in the specified assembly. The Where Clause filter is applied so that only public types are returned. For each public type, a subquery is generated by using the MethodInfo array that is returned from the Type.GetMethods call. These results are filtered to return only those methods whose return type is an array or else a type that implements IEnumerable<T>. Finally, these results are grouped by using the type name as a key.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Training
Module
Perform operations on arrays using helper methods in C# - Training
Use C# helper methods to perform reverse, resize, split and join operations on arrays.
Documentation
LINQ and Reflection - Visual Basic
Learn more about: LINQ and Reflection (Visual Basic)
Query Expression Syntax for Standard Query Operators - Visual Basic
Learn more about: Query Expression Syntax for Standard Query Operators (Visual Basic)