Exemplo n.º 1
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));
        }
Exemplo n.º 4
0
 public object Paste(Type type)
 {
     return(ConversionUtility.Convert(Paste(), type));
 }
Exemplo n.º 5
0
 public static object GetValue(this IGettable gettable, Type type)
 {
     return(ConversionUtility.Convert(gettable.GetValue(), type));
 }