Exemple #1
0
        public object Operate(object operand)
        {
            Ensure.That(nameof(operand)).IsNotNull(operand);

            var type = operand.GetType();

            if (manualHandlers.ContainsKey(type))
            {
                return(manualHandlers[type](operand));
            }

            if (customMethodName != null)
            {
                PopulateUserDefinedOperators(type);

                if (userDefinedOperators[type] != null)
                {
                    operand = ConversionUtility.Convert(operand, userDefinedOperandTypes[type]);

                    return(userDefinedOperators[type].Invoke(null, operand));
                }
            }

            return(CustomHandling(operand));
        }
Exemple #2
0
        private void _Run(object assigner, object assignee)
        {
            var oldValue = this.assignee.Get(assignee);
            var newValue = ConversionUtility.Convert(this.assigner.Invoke(assigner), this.assignee.type);

            this.assignee.Set(assignee, newValue);

            if (!Equals(oldValue, newValue))
            {
                if (assigner is IAssigner _assigner)
                {
                    _assigner.NotifyAssignmentChanged();
                }
            }
        }
        private void EnforceType()
        {
            if (accessor.value?.GetType() == type)
            {
                return;
            }

            accessor.UnlinkChildren();

            if (type == null)
            {
                accessor.value = null;
            }
            else if (ConversionUtility.CanConvert(accessor.value, type, true))
            {
                accessor.value = ConversionUtility.Convert(accessor.value, type);
            }
            else
            {
                accessor.value = type.TryInstantiate();
            }
        }
        public virtual object Operate(object leftOperand, object rightOperand)
        {
            var leftType  = leftOperand?.GetType();
            var rightType = rightOperand?.GetType();

            if (!TryGetOperatorQuery(leftType, rightType, out var query))
            {
                if (leftType == null && rightType == null)
                {
                    return(BothNullHandling());
                }
                else
                {
                    return(SingleNullHandling());
                }
            }

            if (manualHandlers.ContainsKey(query))
            {
                return(manualHandlers[query](leftOperand, rightOperand));
            }

            if (customMethodName != null)
            {
                PopulateUserDefinedOperators(query);

                if (userDefinedOperators[query] != null)
                {
                    leftOperand  = ConversionUtility.Convert(leftOperand, userDefinedOperandTypes[query].leftType);
                    rightOperand = ConversionUtility.Convert(rightOperand, userDefinedOperandTypes[query].rightType);

                    return(userDefinedOperators[query].Invoke(null, leftOperand, rightOperand));
                }
            }

            return(CustomHandling(leftOperand, rightOperand));
        }
Exemple #5
0
 public object Paste(Type type)
 {
     return(ConversionUtility.Convert(Paste(), type));
 }
Exemple #6
0
 public static object GetValue(this IGettable gettable, Type type)
 {
     return(ConversionUtility.Convert(gettable.GetValue(), type));
 }