Đây là vấn đề mới đối với chúng tôi cũng như sau khi cập nhật tệp thực thi nguyên bản và các tệp có liên quan. Đó là hành vi mới mà trước đây chúng tôi chưa từng trải qua.
Sau một đào nhỏ trong csharp.xslt, chúng tôi thấy định nghĩa cho các lĩnh vực 'lặp lại':
<xsl:template match="FieldDescriptorProto[label='LABEL_REPEATED']">
<xsl:variable name="type"><xsl:apply-templates select="." mode="type"/></xsl:variable>
<xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
<xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
private <xsl:if test="not($optionXml)">readonly</xsl:if> global::System.Collections.Generic.List<<xsl:value-of select="$type" />> <xsl:value-of select="$field"/> = new global::System.Collections.Generic.List<<xsl:value-of select="$type"/>>();
[<xsl:apply-templates select="." mode="checkDeprecated"/>global::ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, [email protected]"<xsl:value-of select="name"/>", DataFormat = global::ProtoBuf.DataFormat.<xsl:value-of select="$format"/><xsl:if test="options/packed='true'">, Options = global::ProtoBuf.MemberSerializationOptions.Packed</xsl:if>)]<!--
--><xsl:if test="$optionDataContract">
[global::System.Runtime.Serialization.DataMember([email protected]"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>, IsRequired = false)]
</xsl:if><xsl:if test="$optionXml">
[global::System.Xml.Serialization.XmlElement(@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>)]
</xsl:if>
public global::System.Collections.Generic.List<<xsl:value-of select="$type" />> <xsl:call-template name="pascal"/>
{
get { return <xsl:value-of select="$field"/>; }<!--
--><xsl:if test="$optionXml">
set { <xsl:value-of select="$field"/> = value; }</xsl:if>
}
</xsl:template>
Tôi đã rút khỏi các phần cụ thể cho lĩnh vực tư nhân và setter:
private <xsl:if test="not($optionXml)">readonly</xsl:if> ...snip...
public ...snip...
{
...snip...
<!----><xsl:if test="$optionXml">
set { <xsl:value-of select="$field"/> = value; }
</xsl:if>
}
Lưu ý các điều kiện nghi ngờ ở trên cho $ optionXml. Nếu bạn chỉ cần loại bỏ những người, lĩnh vực này không còn readonly và setter được tạo ra đúng cách.
Vì vậy, nó sau đó trở thành: tin ... snip ...
public ...snip...
{
...snip...
set { <xsl:value-of select="$field"/> = value; }
}
Full 'cố định' mẫu:
<xsl:template match="FieldDescriptorProto[label='LABEL_REPEATED']">
<xsl:variable name="type"><xsl:apply-templates select="." mode="type"/></xsl:variable>
<xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
<xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
private global::System.Collections.Generic.List<<xsl:value-of select="$type" />> <xsl:value-of select="$field"/> = new global::System.Collections.Generic.List<<xsl:value-of select="$type"/>>();
[<xsl:apply-templates select="." mode="checkDeprecated"/>global::ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, [email protected]"<xsl:value-of select="name"/>", DataFormat = global::ProtoBuf.DataFormat.<xsl:value-of select="$format"/><xsl:if test="options/packed='true'">, Options = global::ProtoBuf.MemberSerializationOptions.Packed</xsl:if>)]<!--
--><xsl:if test="$optionDataContract">
[global::System.Runtime.Serialization.DataMember([email protected]"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>, IsRequired = false)]
</xsl:if><xsl:if test="$optionXml">
[global::System.Xml.Serialization.XmlElement(@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>)]
</xsl:if>
public global::System.Collections.Generic.List<<xsl:value-of select="$type" />> <xsl:call-template name="pascal"/>
{
get { return <xsl:value-of select="$field"/>; }
set { <xsl:value-of select="$field"/> = value; }
}
</xsl:template>
tôi chơi với thiết optionXml false, nhưng nó didn' t làm việc và bạn vẫn có thể muốn kích hoạt tùy chọn đó.
Danh sách được tạo thành riêng tư chỉ đọc, tôi đoán tôi chỉ không thấy làm thế nào để gây rối với nó. Tôi sẽ phải xem xét nó sau này mặc dù, chúng tôi sử dụng một cách tiếp cận khác nhau cho vấn đề và tôi quên mất điều này. Có lẽ chỉ là tôi bị mù. Cảm ơn sự giúp đỡ của bạn! Nếu đây là những gì tôi sẽ trở lại và đánh dấu nó trả lời. – Pewsplosions
@user phải có tài sản công cộng. Có phải không? –
Tôi sẽ cập nhật bài đăng chính bằng mã, tôi vẫn chưa có cơ hội để kiểm tra lại. – Pewsplosions