Dear All,
I have to access to the primary key value whatever the class used and without
consider field/property name. Is it possible with AR to access the value of a
PrimaryKey by the attribute name ?
For example :
Class A
{
int _pkA;
[PrimaryKey]
public int PkA
{
get{ return _pkA; }
set{ _pkA = value; }
}
}
Class B
{
int _pkB;
[PrimaryKey]
public int PkB
{
get{ return _pkB; }
set{ _pkB = value; }
}
}
Class Job
{
public obj getPrimaryKey(ActiveRecordBase obj)
{
// have to return the PK value of obj
}
}
I have tried this but it doesn't work with ActiveRecordBase type:
var type = typeof(ActiveRecordBase); // Work with typeof(A)
var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var prop in props)
{
var atts = prop.GetCustomAttributes(typeof(PrimaryKeyAttribute), true);
var propvalue = prop.GetValue(obj, null);
}
Sincerely,
Laurent.
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.