Skip to content

Reference backing fields called "value" using "this.value" - #591

Merged
mganss merged 1 commit into
mganss:masterfrom
3breadt:bugfix/backing-field-with-value-as-name
Mar 13, 2026
Merged

mganss merged 1 commit into
mganss:masterfrom
3breadt:bugfix/backing-field-with-value-as-name

Conversation

@3breadt

@3breadt 3breadt commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Fix incorrect setters generated for collections of elements called "Value" when the no private member prefix is used.

The issue occurs for XSDs such as listed below, when the tool is executed with the --noUnderscore option.

xml version="1.0"?>
<xsd:schema xmlns="http://www.example.org/Values" targetNamespace="http://www.example.org/Values" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:complexType name="TypeWithValueCollection">
        <xsd:sequence>
            <xsd:element name="Value" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
        xsd:sequence>
    xsd:complexType>
xsd:schema>

Code generated before the fix, with a setter that does not change the backing field:

[System.Xml.Serialization.XmlIgnoreAttribute()]
private System.Collections.ObjectModel.Collection<string> value;

[System.Xml.Serialization.XmlElementAttribute("Value")]
public System.Collections.ObjectModel.Collection<string> Value
{
    get
    {
        return value;
    }
    set
    {
        value = value;
    }
}

Code generated after the fix:

[System.Xml.Serialization.XmlIgnoreAttribute()]
private System.Collections.ObjectModel.Collection<string> value;

[System.Xml.Serialization.XmlElementAttribute("Value")]
public System.Collections.ObjectModel.Collection<string> Value
{
    get
    {
        return this.value;
    }
    set
    {
        this.value = value;
    }
}

@codecov

codecov Bot commented Mar 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.31%. Comparing base (38b7792) to head (956ee6f).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #591      +/-   ##
==========================================
+ Coverage   94.23%   94.31%   +0.08%     
==========================================
  Files          33       33              
  Lines        3449     3450       +1     
  Branches      542      543       +1     
==========================================
+ Hits         3250     3254       +4     
+ Misses        126      123       -3     
  Partials       73       73              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mganss
mganss merged commit 0c80ac4 into mganss:master Mar 13, 2026
3 checks passed
@mganss

mganss commented Mar 13, 2026

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants