add convenience function for derived instances so we don't have to allocate an InstanceHandle
This commit is contained in:
parent
e574830852
commit
92b757edc3
@ -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);
|
||||||
|
|||||||
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user