jeudi 11 janvier 2018

Get c# attribute applied to this instance?

Is it possible to retrieve the value of an attribute applied to an instance of a class from within that class? An example of this would be:

class Host {
    [XmlElement("NAME")]
    public ChildClass c { get; set; }
}

[Serializable()]
class ChildClass : IXmlSerializable {
    ...
    void IXmlSerializable.WriteXml(XmlWriter writer) {
        OtherClass desiredElement = ...
        string desiredElementName = ???
        XmlSerializer = new XmlSerializer(desiredElement.GetType(), new XmlRootAttribute(desiredElementName));
        serializer.Serialize(writer, desiredElment);
    }
}

Where desiredElementName should contain NAME?





Aucun commentaire:

Enregistrer un commentaire