0

我有 2 个 ForEach 循环,我正在尝试将它们转换为一个 Linq:

Dim result As Type = Nothing

For Each AssemblyItem As Reflection.Assembly In AppDomain.CurrentDomain.GetAssemblies
    For Each typeItem As Type In AssemblyItem.GetTypes
        If myClass.FullName = typeItem.FullName Then
            result = typeItem
            Exit For
        End If
    Next

    If Not IsNothing(result) Then
        Exit For
    End If
Next

目前我有:

result = AppDomain.CurrentDomain.GetAssemblies()
        .ForEach(Sub(x As Reflection.Assembly) 
                     x.GetTypes().ForEach(Sub(t As Type) 
                                              t.FullName = catalogEntity))

我还尝试了另一种没有运气的方法:

result = AppDomain.CurrentDomain.GetAssemblies()
        .Select(Sub(x) x.GetTypes()
        .Select(Function(y) y.GetType())
        .Where(Function(z) z.FullName.Equals(catalogEntity.FullName))).FirstOrDefault()

但我收到以下错误:

未为“Public Shared Sub ForEach(Of T)(array() As T, action As System.Action(Of T))”的参数“action”指定参数

任何帮助将不胜感激,在此先感谢!

4

1 回答 1

2

这是在VB中:

Dim result as Type = AppDomain.CurrentDomain.GetAssemblies().SelectMany(Function(x) x.GetTypes()).FirstOrDefault(Function(x) x.FullName Is myClass.FullName)

在 C#(我的母语 .NET 语言)中:

Type result = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).FirstOrDefault(x => x.FullName == myClass.FullName);
于 2013-04-27T01:56:27.360 回答