0

我有一个定义了以下类型的 XSD:

<xs:complexType name="AttributeValue">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute name="type"
                type="ns:MyType" 
                default="Value"/>

我想XmlSerializer用这些 attributeValue 类型之一编写一个通过 XSD.exe 创建的 C# 对象。type即使它等于默认值,是否可以强制序列化程序写出属性?

请注意,我无法修改 XSD,我想避免修改通过 XSD.exe 生成的 C# POCO,因为这将在未来发生变化,我想避免维护开销。

4

1 回答 1

1

This is by-design. Here is the reply from MS. Suggested workaround is to comment out/remove the System.ComponentModel.DefaultValueAttribute for the attribute field. The KB article says that "Microsoft plans to change this behavior in the next major version release of the .NET Framework.", but it looks like they didn't.

于 2012-04-26T11:15:00.140 回答