Merge branch 'master' of gitea.azcona-becker.net:mochapowered/mocha-dotnet
This commit is contained in:
commit
e8e5fdb836
@ -31,12 +31,13 @@ public abstract class AttributeImplementation<T> : AttributeImplementation
|
|||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<Type>? ValidDataTypes => [ typeof(T) ];
|
protected override IEnumerable<Type> ValidDataTypes => [ typeof(T) ];
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class AttributeImplementation : ClassImplementation
|
public abstract class AttributeImplementation : ClassImplementation
|
||||||
{
|
{
|
||||||
protected virtual IEnumerable<Type>? ValidDataTypes { get; }
|
protected virtual IEnumerable<Type> ValidDataTypes { get; } = [];
|
||||||
|
protected virtual IEnumerable<Type> ConvertibleDataTypes { get; } = [];
|
||||||
protected abstract object? ConvertFromInternal(Oms oms, object? value);
|
protected abstract object? ConvertFromInternal(Oms oms, object? value);
|
||||||
|
|
||||||
protected virtual object AutoCast(object value)
|
protected virtual object AutoCast(object value)
|
||||||
@ -72,9 +73,22 @@ public abstract class AttributeImplementation : ClassImplementation
|
|||||||
{
|
{
|
||||||
if (value != null && !ValidDataTypes.Contains(value.GetType()))
|
if (value != null && !ValidDataTypes.Contains(value.GetType()))
|
||||||
{
|
{
|
||||||
|
if (ConvertibleDataTypes.Contains(value.GetType()))
|
||||||
|
{
|
||||||
|
// object? p = ConvertFromInternal(oms, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string id = value.ToString();
|
||||||
|
if (value is InstanceHandle ih)
|
||||||
|
{
|
||||||
|
id = oms.GetGlobalIdentifier(ih).ToString("b");
|
||||||
|
}
|
||||||
|
// throw new ArgumentException(String.Format("value {0} cannot be converted to attribute type `{1}` [{2}]", value is string ? "\"" + value.ToString() + "\"" : id, oms.GetInstanceText(attributeInstance), oms.GetInstanceKey(attributeInstance)));
|
||||||
throw new ArgumentException(String.Format("value {0} cannot be converted to attribute type `{1}`", value is string ? "\"" + value.ToString() + "\"" : value, oms.GetInstanceKey(attributeInstance)));
|
throw new ArgumentException(String.Format("value {0} cannot be converted to attribute type `{1}`", value is string ? "\"" + value.ToString() + "\"" : value, oms.GetInstanceKey(attributeInstance)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ValidateInternal(oms, attributeInstance, value);
|
ValidateInternal(oms, attributeInstance, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ namespace Mocha.Core.AttributeImplementations;
|
|||||||
public class BooleanAttributeImplementation : AttributeImplementation<bool>
|
public class BooleanAttributeImplementation : AttributeImplementation<bool>
|
||||||
{
|
{
|
||||||
public override Guid ClassGuid => KnownInstanceGuids.Classes.BooleanAttribute;
|
public override Guid ClassGuid => KnownInstanceGuids.Classes.BooleanAttribute;
|
||||||
|
protected override IEnumerable<Type> ConvertibleDataTypes => [ typeof(string) ];
|
||||||
|
|
||||||
protected override object AutoCast(object value)
|
protected override object AutoCast(object value)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1441,14 +1441,22 @@ public abstract class Oms
|
|||||||
// `Worker who can Resign` := `Current Signed In Worker` -> `Worker who can Resign` = `Steve`
|
// `Worker who can Resign` := `Current Signed In Worker` -> `Worker who can Resign` = `Steve`
|
||||||
|
|
||||||
|
|
||||||
if (IsInstanceOf(assignsToParm, GetInstance(KnownInstanceGuids.Classes.Attribute)) && IsInstanceOf(assignsFromWorkData, GetInstance(KnownInstanceGuids.Classes.Attribute)))
|
if (IsInstanceOf(assignsToParm, GetInstance(KnownInstanceGuids.Classes.Attribute)))
|
||||||
{
|
{
|
||||||
// if `assigns to Parm` is a Class which inherits from Attribute, and `assigns from Work Data` is an Attribute, then assign the underlying work data
|
// if `assigns to Parm` is a Class which inherits from Attribute, and `assigns from Work Data` is an Attribute, then assign the underlying work data
|
||||||
assignsFromWorkDataValue = context.GetWorkData(assignsFromWorkData);
|
if (IsInstanceOf(assignsFromWorkData, GetInstance(KnownInstanceGuids.Classes.Attribute)))
|
||||||
}
|
|
||||||
else if (IsInstanceOf(assignsToParm, GetInstance(KnownInstanceGuids.Classes.Attribute)) && IsInstanceOf(assignsFromWorkData, GetInstance(KnownInstanceGuids.Classes.ReturnAttributeMethodBinding)))
|
|
||||||
{
|
{
|
||||||
assignsFromWorkDataValue = Execute(context, assignsFromWorkData.GetHandle());
|
context.SetWorkData(assignsToParm, context.GetWorkData(assignsFromWorkData));
|
||||||
|
}
|
||||||
|
else if (IsInstanceOf(assignsFromWorkData, GetInstance(KnownInstanceGuids.Classes.ExecutableReturningAttribute)))
|
||||||
|
{
|
||||||
|
InstanceHandle ih = Execute(context, assignsFromWorkData.GetHandle(), null);
|
||||||
|
context.SetWorkData(assignsToParm, context.GetWorkData(ih));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("cannot assign that to an Attribute!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user