Вы всегда можете использовать отражение, чтобы получить атрибут, который применяется к свойству, что-то вроде:
public string GetRealColumn(string objectName, string propertyName)
{
//this can throw if invalid type names are used, or return null of there is no such type
Type t = Type.GetType(objectName);
//this will only find public instance properties, or return null if no such property is found
PropertyInfo pi = t.GetProperty(propertyName);
//this returns an array of the applied attributes (will be 0-length if no attributes are applied
object[] attributes = pi.GetCustomAttributes(typeof(ColumnAttribute));
ColumnAttribute ca = (ColumnAttribute) attributes[0];
return ca.Name;
}
Для краткости и ясности я пропустил проверку ошибок, вы должны добавитьнекоторые, чтобы гарантировать, что это не терпит неудачу во время выполнения.Это не код качества производства.
Кроме того, рефлексия имеет тенденцию быть медленной, поэтому лучше кэшировать результаты.