H
Hans Bampel
Hello group,
i want to overwrite or manipulate a attribute of a property in a
derived class. I use a attribute DBInfo via reflection on my
properties to set the parameters in a SQL-statement dynamically. Now
in a derived class (similar table in the DB), the name of the column a
other one.
what i have
class DBInfoAttribute : Attribute
{
public SqlDbType sqlDbType;
public int length;
public string name;
public DBInfoAttribute(string name, SqlDbType sqlDbType, int length)
{
this.name = name;
this.sqlDbType = sqlDbType;
this.length = length;
}
}
class a
{
protected string name;
[DBInfo("Name", SqlDbType.Varchar, 50)]
public string Name
{
..
}
//something like that
protected void ChangeDbInfoAttribute(string sPropertyName, string
newName,
SqlDbType newSqlDbType, int newLength)
{
PropertyInfo[] piA = this.GetType().GetProperties();
foreach (PropertyInfo pi in piA)
{
if (pi.Name == sPropertyName)
{
DBInfoAttribute dbia = GetDBTypeAttribute(pi);
if (dbia != null)
{
dbia.Name = newName;
dbia.sqlDbType = newSqlDbType;
dbia.length = length;
}
}
}
}
class b : a
{
..//maybe im constructor
ChangeDbInfoAttribute("Name", "Surname", SqlDbType.Varchar, 35)
..
//a call of ChangeDbInfoAttribute is possible, the debugger shows
//the new values till i come out of the scope of
ChangeDbInfoAttribute
}
My actual way is to new-introduce the property Name with other
Attribute-Values.
is it possible to go a way like above?
Thank you & Greetings,
Hans
i want to overwrite or manipulate a attribute of a property in a
derived class. I use a attribute DBInfo via reflection on my
properties to set the parameters in a SQL-statement dynamically. Now
in a derived class (similar table in the DB), the name of the column a
other one.
what i have
class DBInfoAttribute : Attribute
{
public SqlDbType sqlDbType;
public int length;
public string name;
public DBInfoAttribute(string name, SqlDbType sqlDbType, int length)
{
this.name = name;
this.sqlDbType = sqlDbType;
this.length = length;
}
}
class a
{
protected string name;
[DBInfo("Name", SqlDbType.Varchar, 50)]
public string Name
{
..
}
//something like that
protected void ChangeDbInfoAttribute(string sPropertyName, string
newName,
SqlDbType newSqlDbType, int newLength)
{
PropertyInfo[] piA = this.GetType().GetProperties();
foreach (PropertyInfo pi in piA)
{
if (pi.Name == sPropertyName)
{
DBInfoAttribute dbia = GetDBTypeAttribute(pi);
if (dbia != null)
{
dbia.Name = newName;
dbia.sqlDbType = newSqlDbType;
dbia.length = length;
}
}
}
}
class b : a
{
..//maybe im constructor
ChangeDbInfoAttribute("Name", "Surname", SqlDbType.Varchar, 35)
..
//a call of ChangeDbInfoAttribute is possible, the debugger shows
//the new values till i come out of the scope of
ChangeDbInfoAttribute
}
My actual way is to new-introduce the property Name with other
Attribute-Values.
is it possible to go a way like above?
Thank you & Greetings,
Hans