简体   繁体   中英

XML intellisense for C# Class

I create a class like:

public class Employee
{
public int X;
public int Y;
public Color whatever;
}

And I write a XML File for this class like:

<Employee>
    <X>16</X>
    <Y>17</Y>
</Employee>

But I want to have intellisense while writing the xmlFile, it should tell me that I have the attribute X and Y, is there a way to achieve this?

And another question how does the xmlserializer work? Not how I use him, I want to know how they create a xml File with just the class given. Does he use Reflection or what?

And sorry for my bad english ._.

When you have an XSD file declaring the schema of an XML file, you can let Visual Studio provide you with IntelliSense (autocomplete and member information) for editing XML files, as explained in XML Editor IntelliSense Features (see XML Document Validation for setting this up).

See How to create a XSD scheme from a class? to generate an XSD schema from a class.

And yes, basically all serializers use reflection to look up member names and types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM