using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Utils.Attributes { public class AttributesUtil { public static void SetReferenceValue(TClass obj, string referenceProperty, string connectionStr) { var dmoType = obj.GetType(); var propertyInfo = dmoType.GetProperty(referenceProperty); if (!propertyInfo.IsDefined(typeof(DataReferenceAttribute), false)) return; var attrs = propertyInfo.GetCustomAttributes(typeof(DataReferenceAttribute), false); DataReferenceAttribute rAttribute = (DataReferenceAttribute)attrs[0]; var joinProperty = rAttribute.ThisTableJoinProperty; var joinValue = dmoType.GetProperty(joinProperty).GetValue(obj, null).ToString(); var propertyValue = rAttribute.GetValue(joinValue, connectionStr); dmoType.GetProperty(referenceProperty).SetValue(obj, propertyValue, null); } } }