improvements to strict type checking and casting

This commit is contained in:
Michael Becker 2025-10-17 23:03:57 -04:00
parent c648b3c6ad
commit ed912d20cb
2 changed files with 32 additions and 0 deletions

View File

@ -62,6 +62,16 @@ public class BuildAttributeMethodImplementation : MethodImplementation
}
context.SetWorkData(returnsAttribute, value);
}
else if (oms.IsInstanceOf(returnsAttribute, oms.GetInstance(KnownInstanceGuids.Classes.BooleanAttribute)))
{
object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Text.Value)); // initial value
if (value is string)
{
bool val = Boolean.Parse((string)value);
context.SetWorkData(returnsAttribute, val);
}
}
else if (oms.IsInstanceOf(returnsAttribute, oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute)))
{
object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Numeric.Value)); // initial value

View File

@ -67,6 +67,28 @@ public class OmsContext
}
public object? GetWorkData(IInstanceReference parm)
{
object? value = UnsafeGetWorkData(parm);
if (value is string sz)
{
// we really only need to check if we get returned a string like "True" instead of a bool like `false`
// !fixme! move all this hardcoded $@#! into configurable OMS AttributeImplementations
if (Oms.IsInstanceOf(parm, Oms.GetInstance(KnownInstanceGuids.Classes.BooleanAttribute)))
{
value = Boolean.Parse(sz);
}
else if (Oms.IsInstanceOf(parm, Oms.GetInstance(KnownInstanceGuids.Classes.DateAttribute)))
{
value = DateTime.Parse(sz);
}
}
return value;
}
private object? UnsafeGetWorkData(IInstanceReference parm)
{
// this is the former (object GetWorkData(IInstanceReference))
// still providing the underlying implementation of finding the appropriate WD value
// but the public facing replacement function now casts it to the appropriate Attribute
// or Instance Set type if it is not String
if (_WorkData.ContainsKey(parm.GetHandle()))
return _WorkData[parm.GetHandle()];