add convenience function for derived instances so we don't have to allocate an InstanceHandle

This commit is contained in:
Michael Becker 2024-12-21 00:21:14 -05:00
parent e574830852
commit 92b757edc3
2 changed files with 19 additions and 1 deletions

View File

@ -654,6 +654,24 @@ public abstract class Oms
return false; return false;
} }
public T GetAttributeValue<T>(InstanceKey source, InstanceHandle attribute, T defaultValue = default(T), DateTime? effectiveDate = null)
{
if (source.IsDerived)
{
source._oms = this;
Dictionary<InstanceHandle, object?> derivedData = source.GetDerivedData();
if (derivedData.ContainsKey(attribute))
{
return (T) derivedData[attribute];
}
return defaultValue;
}
else
{
InstanceHandle hSource = GetInstance(source);
return GetAttributeValue<T>(hSource, attribute, defaultValue, effectiveDate);
}
}
public T GetAttributeValue<T>(InstanceHandle source, InstanceHandle attribute, T defaultValue = default(T), DateTime? effectiveDate = null) public T GetAttributeValue<T>(InstanceHandle source, InstanceHandle attribute, T defaultValue = default(T), DateTime? effectiveDate = null)
{ {
Dictionary<InstanceHandle, object>? derivedData = GetDerivedData(source); Dictionary<InstanceHandle, object>? derivedData = GetDerivedData(source);

View File

@ -47,7 +47,7 @@ public class DerivedInstanceTests : OmsTestsBase
InstanceHandle ih = Oms.GetInstance(ik); InstanceHandle ih = Oms.GetInstance(ik);
string attVName = Oms.GetAttributeValue<string>(ih, Oms.GetInstance(KnownAttributeGuids.Text.Name)); string attVName = Oms.GetAttributeValue<string>(ik, Oms.GetInstance(KnownAttributeGuids.Text.Name));
Assert.That(attVName, Is.EqualTo(TEST_DERIVED_VALUE)); Assert.That(attVName, Is.EqualTo(TEST_DERIVED_VALUE));
} }