473,386 Members | 1,817 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,386 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 1635

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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.