My task is to get all the properties from a class, find a specific one and associate that property in CSLA business rule as a primary property. However, I don't know how to associate it :( sorry for lack of my knowledge; I'm pretty new to programming.
[Serializable]
public partial class MyClass: BusinessBase<MyClass>
{
private static readonly ValuePropertyInfo<int> MyClassIdProperty = RegisterValueProperty<int>(x => x.MyClassIdProperty);
private static readonly StringPropertyInfo MyClassCodeProperty= RegisterStringProperty(x => x.MyClassCode, new StringPropertyInfoOptions { IsRequired = true, MaxLength = 32 });
And now in my another class, I am only interested in MyClassCodeProperty which I've extracted using reflections like this:
PropertyInfo[] propInfos;
propInfos = typeof(MyClass).GetProperties(BindingFlags.Public | BindingFlags.Static);
Array.Sort(propInfos, delegate (PropertyInfo propInfo1, PropertyInfo propInfo2) { retu propInfo1.Name.CompareTo(propInfo2.Name); });
foreach (PropertyInfo propertyinfo in propInfos)
{
if(propertyinfo.Name == "MyClassCodeProperty")
{
BusinessRules.AddRule(new MyRule{ PrimaryProperty = //? I don't know what goes here });
}
}
I'm not looking for exact answer here but if someone can point me to the right direction, it would be helpful for me. Thanks!
