1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-03-26 22:49:02 +08:00

Added TypeConstraint to check inheritance but inverted.

This commit is contained in:
Simon Rodriguez 2019-11-05 22:47:36 +01:00
parent a825af8192
commit 7f009e1829
2 changed files with 4 additions and 0 deletions

View File

@ -49,6 +49,8 @@ namespace XNode {
Inherited,
/// <summary> Allow only similar types </summary>
Strict,
/// <summary> Allow similar and inherited types but checks inheritance in reverse </summary>
InheritedInverse,
}
#region Obsolete

View File

@ -259,9 +259,11 @@ namespace XNode {
// Check input type constraints
if (input.typeConstraint == XNode.Node.TypeConstraint.Inherited && !input.ValueType.IsAssignableFrom(output.ValueType)) return false;
if (input.typeConstraint == XNode.Node.TypeConstraint.Strict && input.ValueType != output.ValueType) return false;
if (input.typeConstraint == XNode.Node.TypeConstraint.InheritedInverse && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
// Check output type constraints
if (output.typeConstraint == XNode.Node.TypeConstraint.Inherited && !output.ValueType.IsAssignableFrom(input.ValueType)) return false;
if (output.typeConstraint == XNode.Node.TypeConstraint.Strict && output.ValueType != input.ValueType) return false;
if (output.typeConstraint == XNode.Node.TypeConstraint.InheritedInverse && !input.ValueType.IsAssignableFrom(output.ValueType)) return false;
// Success
return true;
}