473,385 Members | 1,798 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,385 software developers and data experts.

Read Field Attributes by Referenced Instance

2
Hi All

I want to read out the properties of a field by the instance, which is referenced by the corresponding field. I want to read out the attributes.

In a class I wrote the following:
Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3.      [MyAttrib(Name="TestA";)]
  4.      private Bb testing1 = new Bb();
  5.  
  6.      [MyAttrib(Name="TestB";)]
  7.      private Bb testing2 = new Bb();
  8. }
  9.  
The two fields create instances of the following class:
Expand|Select|Wrap|Line Numbers
  1. class Bb
  2. {
  3.      {private fields}
  4.  
  5.      public string GetName()
  6.      {
  7.           return (GetMyAttrib.Name) //-> this should return "TestA" or "TestB", dependent of the corresponding instance
  8.      }
  9. }
  10.  
I want to read out the attributes of the fields within the instance of the class Bb to determine which field the present objects is referenced to.
How can I do this?

Or is it possible to inherit the attributes of the fields in A to the corresponding object instance of Bb, so that the attributes are directly binded to the corresponding object?

Thank you
Tom
Apr 2 '09 #1
1 1324
tlhintoq
3,525 Expert 2GB
I think going for attributes is just the long way around.
Just make a property in clas Bb called Name, and retreive that.

Expand|Select|Wrap|Line Numbers
  1.         public class Bd
  2.         {
  3.             public string Name
  4.             {
  5.                 get;
  6.                 set;
  7.             }
  8.         }
  9.  
  10.         public class Ad
  11.         {
  12.             Bd Flintstone = new Bd();
  13.  
  14.             private string GetName()
  15.             {
  16.                 return Flintstone.Name;
  17.             }
  18.         }
  19.  
  20.  
Apr 2 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
3
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their...
1
by: Old Timer | last post by:
I wish to type in a number in my "Code" field, for instance 1060, I then wish the number 1060 to trigger an event that will fill in the next field (township field) For instance, 1060 brings up and...
1
by: Mark | last post by:
Hi, Am trying to write custom validation attributes for public fields, properties, methods etc. using context-bound programming. It works fine for properties, methods, parameters etc. But,...
6
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to...
0
by: Andrew W | last post by:
I am trying to set up a relationship between three fields that make the primary key of two tables. I am able to do this thru the Access Relationships utility, but not thru VBA. I get the message:...
3
by: Mythran | last post by:
http://msdn2.microsoft.com/en-US/library/ms229057(VS.80).aspx * Do not assign instances of mutable types to read-only fields. I would have to disagree with this "Field Design" guidelines...to...
6
by: bill | last post by:
All, I have an unmanaged data structure that I use to pass to an umanaged DLL written in C. This works great. The structure looks sort of like this: unsafe public struct Inputs { .....
23
by: Frank Millman | last post by:
Hi all I have a small problem. I have come up with a solution, but I don't know if it is a) safe, and b) optimal. I have a class with a number of attributes, but for various reasons I cannot...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.