OVH Cloud OVH Cloud

Héritage

1 réponse
Avatar
François Gaumond
Bonjour,

j'ai le problème suivant :

j'ai une classe qui hérite de la classe DataColumn et dans mon application
je fais un foreach sur DataTable.DataColumns ce qui me retourne evidemment
des DataColumn, mais je voudrais caster ces DataColumn dans ma classe
dérivé, j'avais pensé hardcoder une copie de tous les attributs, par
exemple:

Mais il y a certaines propriétés qui sont en readOnly et j'en ai besoin...

Je me demandais s'il n'y avait pas une autre façon de copier le contenue
d'une classe parente autre.

Merci
François

public class DataColumnChild:System.Data.DataColumn
{
private int noAdmin;

private string regEx;

public ColonneDonnee(DataColumn col)
{
this.AllowDBNull = col.AllowDBNull;
this.AutoIncrement = col.AutoIncrement;
this.AutoIncrementSeed = col.AutoIncrementSeed;
this.AutoIncrementStep = col.AutoIncrementStep;
this.Caption = col.Caption;
this.ColumnMapping = col.ColumnMapping;
this.ColumnName = col.ColumnName;
this.Container = col.Container; //READ ONLY
this.DataType = col.DataType;
this.DefaultValue = col.DefaultValue;
this.DesignMode = col.DesignMode; //READ ONLY
this.Expression = col.Expression;
this.ExtendedProperties = col.ExtendedProperties; //READ ONLY
this.MaxLength = col.MaxLength;
this.Namespace = col.Namespace;
this.Ordinal = col.Ordinal; //READ ONLY
....
}

1 réponse

Avatar
Paul Bacelar
Pouvez-vous être plus loquace sur votre problème, car votre solution de
dupliquer les attributs de la classe de base contrevient aux paradigmes de
la conception objet.

En claire, pourquoi ne pas dérivé de DataColumn et ajouter les propriétés et
fonctionnalités nécessaires?
--
Paul Bacelar


"François Gaumond" wrote in message
news:
Bonjour,

j'ai le problème suivant :

j'ai une classe qui hérite de la classe DataColumn et dans mon application
je fais un foreach sur DataTable.DataColumns ce qui me retourne evidemment
des DataColumn, mais je voudrais caster ces DataColumn dans ma classe
dérivé, j'avais pensé hardcoder une copie de tous les attributs, par
exemple:

Mais il y a certaines propriétés qui sont en readOnly et j'en ai besoin...

Je me demandais s'il n'y avait pas une autre façon de copier le contenue
d'une classe parente autre.

Merci
François

public class DataColumnChild:System.Data.DataColumn
{
private int noAdmin;

private string regEx;

public ColonneDonnee(DataColumn col)
{
this.AllowDBNull = col.AllowDBNull;
this.AutoIncrement = col.AutoIncrement;
this.AutoIncrementSeed = col.AutoIncrementSeed;
this.AutoIncrementStep = col.AutoIncrementStep;
this.Caption = col.Caption;
this.ColumnMapping = col.ColumnMapping;
this.ColumnName = col.ColumnName;
this.Container = col.Container; //READ ONLY
this.DataType = col.DataType;
this.DefaultValue = col.DefaultValue;
this.DesignMode = col.DesignMode; //READ ONLY
this.Expression = col.Expression;
this.ExtendedProperties = col.ExtendedProperties; //READ ONLY
this.MaxLength = col.MaxLength;
this.Namespace = col.Namespace;
this.Ordinal = col.Ordinal; //READ ONLY
....
}