473,395 Members | 2,436 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,395 software developers and data experts.

Trying to Use System.Attribute and Reflection to return Property for use

I am looking to use a field attribute in a to find and use a property. If given
Find("Record Artist", "Billy Joel");
I am looking to find the first instance in the collection where the value
the property -=> Artist <=-( because of the Attribute "Record Artist")
equals "Billy Joel".

I didn't know if this is possible.

Please keep in mind that I know I need to take care of data types and
error detection/correction. I am trying to simplify this as much as possible.

Thanks,
Dave

Da**********@BellSouth.net
###########################################
public int Find(string fieldName, string fieldValue)
{
RecordAlbumCollection collection = myCollection;

object[] attribs = j.GetType().GetCustomAttributes(typeof(FieldNameTe xt), false);
FieldNameText field = attribs[0] as FieldNameText;

// Find the Property Name
foreach (FieldNameText f in field)
{
if (fieldName.Equals(f.FieldName))
{
// save SOMEPROPERTY
break;
}
}

foreach (RecordAlbum album in collection)
{
if (album.SOMEPROPERTY.Equals(fieldValue) == 0
return (album);
}

return null;
}

###########################################

public class RecordAlbum
{
private string m_artist;
private string m_albumtitle;
private string m_song;

[FieldNameText( "Record Artist")]
public string Artist {get {return m_artist;} set {m_artist = value;}}

[FieldNameText( "Record Title")]
public string Artist {get {return m_albumtitle;} set {m_albumtitle= value;}}

[FieldNameText( "Record Song")]
public string Artist {get {return m_song;} set {m_song= value;}}

}

###########################################

[System.AttributeUsage( AttributeTargets.Field )]
public class FieldNameText : System.Attribute
{
// Data Members
private string m_fieldName;

// Properties
public string FieldName { get { return m_fieldName; }}

public FieldNameText( string fieldName )
{
m_fieldName = fieldName;
}
}
Jul 19 '05 #1
0 1636

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

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
3
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We...
4
by: Ben Blair | last post by:
Hi. How does one assign a custom parameter attribute to the implicit "value" parameter of the set accessor method of a property? For example, I can assign a custom attribute to the return...
5
by: Lance | last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user...
0
by: David Elliott | last post by:
I am looking to use a field attribute in a to find and use a property. If given Find("Record Artist", "Billy Joel"); I am looking to find the first instance in the collection where the value the...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
2
by: Jay | last post by:
Is there a way to access the actual datatype of a property when looking at the PropertyInfo? For example: Property defined: public Nullable<DateTimeEndDate { get { return endDate; }
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.