不要尝试在模式中使用匿名类型。
C#团队使得匿名类型稳定下来。
Taking the direct route, the C# team made anonymous types immutable.
我们为何不喜欢清单4中的匿名类型?
这是匿名类型的主要问题。
匿名类型有什么问题?
基于以下几个原因,应该避免使用匿名类型。
还是必须对匿名类型进行命名。
什么是匿名类型?
讨论匿名类型结构比讨论命名类型结构更加困难。
Structures of anonymous types are more difficult to discuss than structures of named types.
当映射必须命名匿名类型时,它们可能会引起问题;
they may cause problems when a mapping must name anonymous types;
因此,如果您可以自由修改架构,最好避免匿名类型。
So if you have the freedom to modify the schemas, it is best to avoid anonymous types.
对于局部元素或匿名类型,目前不能使用可重用映射。
In the case of local elements or anonymous types, reusable mappings are not an option at this time.
可以通过将匿名类型转换为命名类型来解决这些问题。
These issues can be remedied by converting anonymous types to named types.
如何重用数据转换成一个匿名类型宣言吗?
一种复合型和匿名类型之间的区别是什么?
What's the difference between a compound type and an anonymous type?
submap细化不可用于处理局部元素或匿名类型。
The Submap refinement is not available when working with local elements or anonymous types.
使用类型引用和匿名类型的结构子类型转化(动态类型)。
Structural Subtyping (duck typing) using type inference and anonymous types.
此查询在编写时本来可以不投影到第一个匿名类型。
This query could have been written without projecting to the first anonymous type.
按照以下步骤,将清单1中的匿名类型转换为清单2中的命名类型。
We followed these steps to transform listing 1's anonymous type into listing 2's named type.
本文将总结使用匿名类型可能会引起的问题,希望读者能够避免它们。
This article codifies issues that may arise from using anonymous types in hopes that readers will avoid them.
VB和C#之所以能不同的实现方式是因为匿名类型是一个编译器特性。
The reason VB and C# can use different implementations is that anonymous types are a compiler feature.
JAXB非常稳健,可允许您通过绑定文件来命名需要命名的匿名类型。
JAXB is robust enough to allow you to name anonymous types as you need to via the binding file.
匿名类型的名称由编译器生成,并可能随编译的不同而不同。
The name of the anonymous type is compiler generated, and it may vary from compilation to compilation.
当创建匿名类型时,程序员可以用关键词“Key”表示哪些字段是稳定的。
When creating anonymous classes, programmers can use the modifier "Key" to indicate which fields are immutable.
在清单8的例子中,我们定义了一个匿名类型,没有明确地命名这个复杂类型。
In the example in Listing 8, we have defined what is called an anonymous type, where no explicit name is given to the complex type.
CLR自己对匿名类型没有什么概念,只是把它们看作有着自动产生名字的普通类。
The CLR itself doesn't have any notion of anonymous types and sees them as normal classes with automatically generated names.
有同样属性名和类型的两个匿名类型对象将被指派为自动生成的同样的类。
Two anonymously typed objects that have the same property names and types will be assigned to the same automatically generated class.
请注意,在此特定示例中,最终的输出不是组,而是匿名类型的平面序列。
Note that in this particular example the final output is not a group, but a flat sequence of anonymous types.
但我们认为,匿名类型没有命名类型那样的可读性;深层嵌套的XML结构通常难以理解。
But in our opinion, anonymous types aren't as readable as named types; a deeply nested XML structure is almost always more difficult to understand readily.
类型推断—使用匿名类型时,关键字var必不可少。它还能减少你其他变量声明中的冗余。
Type Inference - the var keyword, which is necessary when using anonymous types, can also reduce redundancy in your other variable declarations.
应用推荐