You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

24 lines
898 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Utils.Attributes
{
public class AttributesUtil
{
public static void SetReferenceValue<TClass>(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);
}
}
}