If you want to do it with reflection, it is not that difficult actually. I have played quite a bit with reflection using both SS and adapter patterns..
Your sample would look maybe something like this:
private void junk(IEntityCollection tableAorBItems, int encounterId, int hdrId, int parentId, string entityName)
{
IRelationCollection relations = new RelationCollection();
PropertyInfo relationsProperty = tableAorBItems.GetType().GetProperty("Relations");
Object relationsObject = relationsProperty.GetValue(null, null);
PropertyInfo LstItemsEntityUsingLListIdProperty = relationsObject.GetType().GetProperty("LstItemsEntityUsingLListId");
IEntityRelation LstItemsEntityUsingLListIdValue = (IEntityRelation)LstItemsEntityUsingLListIdProperty.GetValue(null,null);
relations.Add(LstItemsEntityUsingLListIdValue, JoinHint.Left);
ObjectHandle col = Activator.CreateInstance("assemblyname", "rootnamespace.EntityClasses." + entityName);
IEntity entity = (IEntity)col.Unwrap();
IPredicateExpression firstselect = new PredicateExpression();
EntityField entityField = (entity.Fields["LEncounterId"] as EntityField).Clone() as EntityField;
firstselect.Add(entityField == encounterId);
entityField = (entity.Fields["LListHeaderId"] as EntityField).Clone() as EntityField;
firstselect.Add(entityField == hdrId);
entityField = (entity.Fields["LParentId"] as EntityField).Clone() as EntityField;
firstselect.Add(entityField == parentId);
entityField = (entity.Fields["BDeletedFl"] as EntityField).Clone() as EntityField;
firstselect.Add(entityField == false);
entityField = (entity.Fields["LAddendumId"] as EntityField).Clone() as EntityField;
//watch out for addendums
firstselect.AddWithAnd(entityField == 0);
tableAorBItems.GetMulti(firstselect, -1, null, relations);
foreach (IEntity ent in tableAorBItems)
{
//This wont work.. just put it here to get the idea. Either use reflection for LstItems or
//wrap with interface to partial class for both entities.
if (ent.Fields["SDescriptionTx"].CurrentValue == ent.LstItems.SDescriptionTx)
{
return ent.Fields["DtLastUpdateDt"].CurrentValue;
}
}
}
I did not test this code or anything and I am not sure if you can use PropertyInfo.GetValue(null, null) for static types, but it should be doable somehow if that does not work.
And as mentioned in the comment part, you could put the relations behind your own interface, so you could acccess them without reflection.