English 中文(简体)
为什么让成员的行为不一致?
原标题:Why does getting members behave inconsistently?

在试图以某种汇编方式收集各类材料时,我全心全意地混淆了解决这一问题的方法。 基本上,似乎回报结果的方法没有,反之亦然。 下面是“速成”会议的产出,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;
最佳回答

我认为,这只是一个与罗斯林无关的直接窗口的限制。

例如,以下法典:

var ints = new object[] { 2 }.OfType<int>();

我把这一产出放在眼前窗口:

ints
{System.Linq.Enumerable.OfTypeIterator<int>}
    source: null
    System.Collections.Generic.IEnumerator<TResult>.Current: 0
    System.Collections.IEnumerator.Current: 0

但是,如果我使用<代码>foreach对收集工作进行检索,或使用成果 在观察窗口中的观点是正确的。

你看到的理由是:<代码>数字。 OfType ( is written using an iterator/2005/4, which have the iterator category. 激光器类型有些领域,名称不易懂,包括<代码><>3__source,持有原始来源(如我的阵列)。 它还有一个正常名称的领域:source,该名称载于GetE amountator()。 由于您没有提及这一方法,source> 。

问题回答

暂无回答




相关问题
Howto get started with C# 4.0 and .NET 4.0?

I don t want to download Visual Studio 2010. How can I start studying (not developing real applications) C# 4.0 and .NET 4.0 with just a text editor? Can I just download C# 4.0 compiler and .NET 4.0 ...

Mocking Framework with C# 4.0 Support?

Anybody know of a mocking framework that supports C# 4.0? Doesn t matter which one ATM, just need something that will work.

Unit Testing interface contracts in C#

Using the Code Contracts tools available in VS2010 Beta 2, I have defined an interface, a contract class for that interface and two classes that implement the interface. Now when I come to test the ...

How to Iterate Through Array in C# Across Multiple Calls

We have an application where we need to de-serialize some data from one stream into multiple objects. The Data array represents a number of messages of variable length packed together. There are no ...

IronPython ScriptRuntime equivalent to CPython PYTHONPATH

The following import works inside ipy.exe prompt but fails using IronPython ScriptRuntime inside a C# 4.0 program. import ConfigParser C# code: using System; using System.Collections.Generic; using ...

i cant understand the following code

Matrix<float> trainData2 = trainData.GetRows(intVar >> 1, intVar, 1); intVar is integer type... please help me to understand this code.

热门标签