Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a simple way to make a property value to appear as element name? #89

Closed
douglasgdy opened this issue Mar 15, 2018 · 2 comments
Closed

Comments

@douglasgdy
Copy link

For example, I have a class as follows:

public class Person
{
    public string SSN { get; set; } = "SSN-Value";

    [YAXAttributeForClass]
    public string Name { get; set; } = "Name-Value";
}

I hope that can be serialized to:
<SSN-Value Name="Name-Value" />

@acvanzant
Copy link

You're asking to have a dynamic value as the tag itself? That would mean the schema itself changes depending on the data. XML doesn't work that way.

However, you can use any arbitrary tag defined ahead of time but it must not depend upon the data.

You could use the YAXValueFor attribute in the containing object instead of creating a Person class.

public Record 
{   
   [YAXSerializeAs("SSN-Value")]
   public PersonSSN {get;set;} = "XXX-XX-XXXX";

   [YAXValueForAttribute("SSN-Value#Name")]
   public PersonName {get;set;} = "Guys Name";
}

outputs
<SSN-Value Name="Guys Name">XXX-XX-XXXX</SSN-Value>

@douglasgdy
Copy link
Author

@acvanzant Thank you for answer.

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

No branches or pull requests

2 participants