471,092 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Overwriting of Property-Attributes in a Derived Class

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
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

My actual way is to new-introduce the property Name with other
is it possible to go a way like above?

Thank you & Greetings,
Nov 16 '05 #1
1 1938
In article <73**************************@posting.google.com >, web-
ac******@gmx.de says...
i want to overwrite or manipulate a attribute of a property in a
derived class.

You can't. Attributes are placed in the metadata and used by the
runtime. Sure you can *look* at the attributes via code, but you can't
change them.

Patrick Steele
Microsoft .NET MVP
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ellixis | last post: by
reply views Thread by Peter Royle | last post: by
19 posts views Thread by tweak | last post: by
11 posts views Thread by Steven Jones | last post: by
1 post views Thread by Kyote | last post: by
2 posts views Thread by Nemisis | last post: by
6 posts views Thread by Gregor Horvath | last post: by
27 posts views Thread by Jason | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.