在试图以某种汇编方式收集各类材料时,我全心全意地混淆了解决这一问题的方法。 基本上,似乎回报结果的方法没有,反之亦然。 下面是“速成”会议的产出,appCompilation
为“代码>Compilation(natch)。
**appCompilation.GlobalNamespace.GetMembers()**
Count = 14
[0]: "Namespace Registration"
[1]: "Namespace Payments"
[2]: "Namespace Foo"
[3]: "NamedType <Module>"
[4]: "NamedType <Module>"
[5]: "NamedType <Module>"
[6]: "NamedType <Module>"
[7]: "NamedType <Module>"
[8]: "NamedType <Module>"
[9]: "NamedType <Module>"
[10]: "Namespace Conference"
[11]: "Namespace System"
[12]: "NamedType <>f__AnonymousType0<<OrderId>j__TPar>"
[13]: "Namespace Infrastructure"
**appCompilation.GlobalNamespace.GetTypeMembers()**
{System.Linq.Enumerable.OfTypeIterator<Roslyn.Compilers.CSharp.NamedTypeSymbol>}
source: null
**appCompilation.GlobalNamespace.GetNamespaceMembers()**
{System.Linq.Enumerable.OfTypeIterator<Roslyn.Compilers.CSharp.NamespaceSymbol>}
source: null
So my question is this:
When I call .GetTypeMembers()
on a Symbol of Kind
== Namespace
, I get null.
When I call .GetNamespaceMembers()
for the same symbol, I also get null.
Yet, when I call .GetMembers()
I get namespaces and types galore!
更有甚者,我可以把这一发言放在一个观察窗口上,取得非致命、非致命的成果!
appCompilation. GlobalNamespace.GetNamespace Memberss(), results
Possibly relevant:
Initiating execution of a query doesn t seem to happen when I expect, but I m not exactly sure how that how or even why I should have to worry about that... calling .ToList()
sometimes will trigger execution. I had thought that even though many methods provide a CancellationToken
parameter, they all run synchronously. A problem too is that the various GetXXX()
methods return either ReadOnlyArray
or IEnumerable
; the read-only doesn t seem to pick up the same behavior from the LINQ extension methods the same way that IEnumerable does.
从分解输出表面扫描来看,它喜欢<代码>。 GetType Memberss and its ilk Packcode>Get Memberss( with an . OfType<>
calls。 难道这在翻译中是浪费了吗?
不管怎么说,获得和执行询问的不一致是令人痛苦的,因此,我希望有人能够帮助我了解我所失踪的、造成事情似乎不现实的东西。
EDIT:在反对该词之后,我发现,你只是要通过象征树进行重新搜索,而问询会是一种比Mlambda语有时会更容易的办法......和oh 是,因为眼前的窗口似乎阻碍着更多的努力。
最终通过查询样本,从特定汇编中检索所有类型,最高可达到三个名称空间点(需要更多的测试以涵盖这些案件):
从这一点来看(这远远胜于其他一些尝试!)
appCompilation.Assembly.GlobalNamespace.GetNamespaceMembers()
.SelectMany(x => x.GetNamespaceMembers().Select(y => y.GetNamespaceMembers()))
.SelectMany(x => x, (symbols, symbol) => symbol.GetTypeMembers())
.SelectMany(x => x);
为此(没有完全恢复,但现在做得够好):
from glob in appCompilation.Assembly.GlobalNamespace
.GetMembers()
.OfType<NamespaceOrTypeSymbol>()
from childNs in glob
.GetMembers()
.OfType<NamespaceSymbol>()
from childTypes in childNs
.GetTypeMembers()
select childTypes;