improvements to strict type checking and casting
This commit is contained in:
parent
c648b3c6ad
commit
ed912d20cb
@ -62,6 +62,16 @@ public class BuildAttributeMethodImplementation : MethodImplementation
|
|||||||
}
|
}
|
||||||
context.SetWorkData(returnsAttribute, value);
|
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)))
|
else if (oms.IsInstanceOf(returnsAttribute, oms.GetInstance(KnownInstanceGuids.Classes.NumericAttribute)))
|
||||||
{
|
{
|
||||||
object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Numeric.Value)); // initial value
|
object? value = oms.UnsafeGetAttributeValue(method, oms.GetInstance(KnownAttributeGuids.Numeric.Value)); // initial value
|
||||||
|
|||||||
@ -67,6 +67,28 @@ public class OmsContext
|
|||||||
}
|
}
|
||||||
public object? GetWorkData(IInstanceReference parm)
|
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()))
|
if (_WorkData.ContainsKey(parm.GetHandle()))
|
||||||
return _WorkData[parm.GetHandle()];
|
return _WorkData[parm.GetHandle()];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user