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;
}
}