private void SetStaticValue(object?staticValue) { RightPath?.Dispose(); RightPath = null; // If the left side is empty simply apply the value, any validation will wait if (LeftPath == null || !LeftPath.IsValid) { RightStaticValue = staticValue; return; } // If the left path is valid we can expect a type Type leftSideType = LeftPath.GetPropertyType() !; // If not null ensure the types match and if not, convert it if (staticValue != null && staticValue.GetType() == leftSideType) { RightStaticValue = staticValue; } else if (staticValue != null) { RightStaticValue = Convert.ChangeType(staticValue, leftSideType); } // If null create a default instance for value types or simply make it null for reference types else if (leftSideType.IsValueType) { RightStaticValue = Activator.CreateInstance(leftSideType); } else { RightStaticValue = null; } }
/// <summary> /// Updates the right side of the predicate, makes the predicate static and re-compiles the expression /// </summary> /// <param name="staticValue">The right side value to use</param> public void UpdateRightSideStatic(object?staticValue) { PredicateType = ProfileRightSideType.Static; RightPath?.Dispose(); RightPath = null; SetStaticValue(staticValue); }
/// <inheritdoc /> protected override void Dispose(bool disposing) { ConditionOperatorStore.ConditionOperatorAdded -= ConditionOperatorStoreOnConditionOperatorAdded; ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved; LeftPath?.Dispose(); RightPath?.Dispose(); base.Dispose(disposing); }
/// <summary> /// Updates the right side of the predicate using a path and makes the predicate dynamic /// </summary> /// <param name="path">The path pointing to the right side value</param> public void UpdateRightSideDynamic(DataModelPath?path) { if (path != null && !path.IsValid) { throw new ArtemisCoreException("Cannot update right side of predicate to an invalid path"); } RightPath?.Dispose(); RightPath = path != null ? new DataModelPath(path) : null; PredicateType = ProfileRightSideType.Dynamic; }
/// <summary> /// Updates the right side of the predicate, makes the predicate dynamic and re-compiles the expression /// </summary> /// <param name="path">The path pointing to the right side value inside the data model</param> public void UpdateRightSideDynamic(DataModelPath?path) { if (path != null && !path.IsValid) { throw new ArtemisCoreException("Cannot update right side of predicate to an invalid path"); } if (Operator != null && path != null && !Operator.SupportsType(path.GetPropertyType() !, ConditionParameterSide.Right)) { throw new ArtemisCoreException($"Selected operator does not support right side of type {path.GetPropertyType()!.Name}"); } RightPath?.Dispose(); RightPath = path != null ? new DataModelPath(path) : null; PredicateType = ProfileRightSideType.Dynamic; }
/// <summary> /// Updates the right side of the predicate, makes the predicate static and re-compiles the expression /// </summary> /// <param name="staticValue">The right side value to use</param> public void UpdateRightSideStatic(object?staticValue) { PredicateType = ProfileRightSideType.Static; RightPath?.Dispose(); RightPath = null; // If the operator is null simply apply the value, any validation will wait if (Operator == null) { RightStaticValue = staticValue; return; } // If the operator does not support a right side, always set it to null if (Operator.RightSideType == null) { RightStaticValue = null; return; } // If not null ensure the types match and if not, convert it Type?preferredType = GetPreferredRightSideType(); if (staticValue != null && staticValue.GetType() == preferredType || preferredType == null) { RightStaticValue = staticValue; } else if (staticValue != null) { RightStaticValue = Convert.ChangeType(staticValue, preferredType); } // If null create a default instance for value types or simply make it null for reference types else if (preferredType.IsValueType) { RightStaticValue = Activator.CreateInstance(preferredType); } else { RightStaticValue = null; } }