Merci pour votre aide.
Voilà la solution que j'ai implémenté:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
public void Load(XmlReader xrReader)
{
// Get the type and the properties
Type tType = this.GetType();
PropertyInfo[] piProperties = tType.GetProperties();
// Create a serializer
XmlSerializer xsSerializer = new XmlSerializer(tType);
// Deserialize
BaseClass oCurrentObject = (BaseClass)xsSerializer.Deserialize(xrReader);
// For each property of T
foreach(PropertyInfo piProperty in piProperties)
{
if(piProperty.CanWrite)
{
// Get the value
object oValue = piProperty.GetValue(oCurrentObject, null);
// Set the property value
piProperty.SetValue(this, oValue, null);
}
}
} |
PS: si vous avez des infos sur le fonctionnement de la méthode GetProperties, je suis preneur.... Par ce que à chaque fois que j'utilise un paramètre BindingFlags, cela ne fonctionne pas 
dans le cas présent j'ai essayé :
tType.GetProperties(BindingFlags.SetProperty);
et
tType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);
ni l'un ni l'autre ne me renvoie les propriétés ayant un set
Partager