1
votes

I have the following

[XmlType("Settings")]
public class Settings
{
    [XmlElement("Directory")]
    public string Directory { get; set; }

    public Settings()
    {
        Directory = "/"
    }
}

But when my program is obfuscated it complains about it not being CLS-compliant. I thought declaring the names in an attribute would work but apparently not. Is there a way to fix this without excluding it from obfuscating? Also how do you remove the stuff like

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1

1 Answers

0
votes

One possible way would be to build the model at runtime use XmlAttributeOverrides (and caching the final XmlSerializer, which is essential when using approach). The minor problem here being that you need to tell it member-names as strings, but there are ways of doing that with the Expression API such that use can use something like GetMemberName<Foo>(foo => foo.Bar). Since expression trees operate with the MemberInfo directly, this should return the obfuscated name, not "Bar".