473,378 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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
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
Nov 16 '05 #1
1 2047
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
http://weblogs.asp.net/psteele
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ellixis | last post by:
Hello, How can I use fwrite() and fseek() in order to write data in the middle (or anywhere else) of a file without overwriting existing data ? People told me that I should load the file into...
0
by: Peter Royle | last post by:
Hello, I have a deployment project (VB.NET - I don't know whether the language matters) and I have a file in it which goes in the user's folder. This file gets modified by the application, so I...
19
by: tweak | last post by:
I have been messing around with buffers, and I found it peculiar that the code below will run without a segmentation fault. As far as I know, overwriting the allocated space from a call to...
11
by: Steven Jones | last post by:
I have a C program that prints out two lines as follows: Line 1 Line 2 What I would like is for this program to sleep for one second, and then print out two more lines, overwriting the...
8
by: Yuk Tang | last post by:
I am tearing my hair out over this, since I can't see what I'm doing wrong (duh, if I knew, I wouldn't be asking the question). I am adding Field items to a Field Collection, but for some reason...
1
by: Kyote | last post by:
I'm wanting to copy/move files from 1 directory to another in my program. I'm even doing a bit of renaming to help these specific files conform slightly to my preferred naming conventions to help...
2
by: Nemisis | last post by:
Hi everyone, I have 2 pages, PageA and PageB. On PageA i allow our users to update a details of a record using textboxes, dropdownlists etc. When a user clicks on a button on PageA, i would...
4
by: QntmPg | last post by:
Hi all, I have read through what I could find on previous questions regarding using the OpenArgs property, but I'm still not able to get my form to open correctly. I'm not sure exactly where the...
6
by: Gregor Horvath | last post by:
Hi, why is this code failing? class B(object): pass B.testattr = property(lambda s:"hallo") b = B() b.testattr = "test"
27
by: Jason | last post by:
Hi, I need to open an existing file, seek to a position at X number of bytes, and write out Y number of bytes overwriting any existing bytes, but no erasing any other data. Is this possible? ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.