コード例 #1
0
        private bool CompareValue(float value)
        {
            switch (compareOp)
            {
            case CompareOp.Equal:
                return(value == IntValue);

            case CompareOp.NotEqual:
                return(value != IntValue);

            case CompareOp.GreaterThan:
                return(value > IntValue);

            case CompareOp.GreaterThanOrEqual:
                return(value >= IntValue);

            case CompareOp.LessThan:
                return(value < IntValue);

            case CompareOp.LessThanOrEqual:
                return(value <= IntValue);

            default:
                throw new NotImplementedException(compareOp.ToString());
            }
        }
コード例 #2
0
        public void TestCompareOpConstructor01()
        {
            CompareResult compareResult = CompareResult.Less;
            CompareOp     compareOp     = new CompareOp(compareResult);

            compareOp.ToString();
        }
コード例 #3
0
        public override bool IsValid(object target, object value)
        {
            ErrorMessage = null;
            const string errorText = "The value {0} must {1} {2}.";

            IComparable source = (IComparable)value;

            if (!CompareHelper.Compare(Op, source, CompareTo))
            {
                ErrorMessage = string.Format(errorText, source, Op.ToString(), CompareTo);
                return(false);
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Evalaute this node and return result.
        /// </summary>
        /// <param name="thisObject">Reference to object that is exposed as 'this'.</param>
        /// <returns>Result value and type of that result.</returns>
        public override EvalResult Evaluate(object thisObject)
        {
            // Always evaluate the first child
            EvalResult left = this[0].Evaluate(thisObject);

            // We can only handle a boolean result
            if (left.Type != TypeCode.Boolean)
            {
                // Try and perform implicit conversion to a boolean
                if (ImplicitConverter.CanConvertToBoolean(left.Value, _language))
                {
                    left.Type  = TypeCode.Boolean;
                    left.Value = ImplicitConverter.ConvertToBoolean(left.Value, _language);
                }
                else
                {
                    throw new ApplicationException("Operator '" + OperationString + "' can only operate on 'bool' types.");
                }
            }

            switch (Operation)
            {
            case CompareOp.Or:
                // If 'true' then there is no need to evaluate the right side
                if ((bool)left.Value)
                {
                    return(left);
                }
                break;

            case CompareOp.And:
                // If 'false' then there is no need to evaluate the right side
                if (!(bool)left.Value)
                {
                    return(left);
                }
                break;

            default:
                throw new ApplicationException("Unimplemented conditional logical operator '" + Operation.ToString() + "'.");
            }

            // Need to evaluate the second child
            left = this[1].Evaluate(thisObject);

            // We can only handle a boolean result
            if (left.Type != TypeCode.Boolean)
            {
                // Try and perform implicit conversion to a boolean
                if (ImplicitConverter.CanConvertToBoolean(left.Value, _language))
                {
                    left.Type  = TypeCode.Boolean;
                    left.Value = ImplicitConverter.ConvertToBoolean(left.Value, _language);
                }
                else
                {
                    throw new ApplicationException("Operator '" + OperationString + "' can only operate on 'bool' types.");
                }
            }

            // Just return whatever the result is as the result of the conditional operation
            return(left);
        }
コード例 #5
0
ファイル: QCParams.cs プロジェクト: xuanximoming/key
 /// <summary>
 /// 比较符至字符串(保证可以用来标记分隔)
 /// </summary>
 /// <param name="op"></param>
 /// <returns></returns>
 public static string CompareOp2String(CompareOp op)
 {
     return("<" + op.ToString() + ">");
 }
コード例 #6
0
    public bool CheckTransition(CharacterAnimation animation, bool currentStateEnabled)
    {
        switch (type)
        {
        case TransitionType.None:
            return(true);

        case TransitionType.Bool:
            return(animation.GetParameter <bool>(name) == boolValue);

        case TransitionType.Float:
        {
            var parameter = animation.GetParameter <float>(name);
            switch (compareOp)
            {
            case CompareOp.Equal:
                return(parameter == floatValue);

            case CompareOp.NotEqual:
                return(parameter != floatValue);

            case CompareOp.GreaterThan:
                return(parameter > floatValue);

            case CompareOp.GreaterThanOrEqual:
                return(parameter >= floatValue);

            case CompareOp.LessThan:
                return(parameter < floatValue);

            case CompareOp.LessThanOrEqual:
                return(parameter <= floatValue);

            default:
                throw new NotImplementedException(compareOp.ToString());
            }
        }

        case TransitionType.Int:
        {
            var parameter = animation.GetParameter <int>(name);
            switch (compareOp)
            {
            case CompareOp.Equal:
                return(parameter == intValue);

            case CompareOp.NotEqual:
                return(parameter != intValue);

            case CompareOp.GreaterThan:
                return(parameter > intValue);

            case CompareOp.GreaterThanOrEqual:
                return(parameter >= intValue);

            case CompareOp.LessThan:
                return(parameter < intValue);

            case CompareOp.LessThanOrEqual:
                return(parameter <= intValue);

            default:
                throw new NotImplementedException(compareOp.ToString());
            }
        }

        case TransitionType.String:
            //parameter.stringValue = animation.GetParameter<string>(name);
            break;

        case TransitionType.Time:
            return(!currentStateEnabled);
        }

        return(false);
    }