472,353 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 1571

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,...
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...
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...
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...
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...
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...
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...
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...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.