コード例 #1
0
        protected override void ProcessArg(Evaluator evaluater, Result[] argArray)
        {
            base.ProcessArg(evaluater, argArray);
            Type type0 = argArray[0].Type;
            Type type1 = argArray[1].Type;
            int  result;

            if (type0 == null && type1 == null)
            {
                return;
            }

            if (type0 == null)
            {
                if (type1.IsValueType)
                {
                    throw new InvalidCastException(string.Format("from null to {0}", type1.Name));
                }

                if (type1 == typeof(string))
                {
                    argArray[0].Type = typeof(string);
                    return;
                }
                else
                {
                    throw new InvalidCastException(string.Format("from null to {0}", type1.Name));
                }
            }

            if (type1 == null)
            {
                if (type0.IsValueType)
                {
                    throw new InvalidCastException(string.Format("from null to {0}", type0.Name));
                }

                if (type0 == typeof(string))
                {
                    argArray[1].Type = typeof(string);
                    return;
                }
                else
                {
                    throw new InvalidCastException(string.Format("from null to {0}", type0.Name));
                }
            }

            if (BinaryHelper.ComparePrimitiveType(type0, type1, out result))
            {
                if (result > 0)
                {
                    argArray[1].Value = ConvertHelper.ChangeType(argArray[1].Value, type0);
                }
                else if (result < 0)
                {
                    argArray[0].Value = ConvertHelper.ChangeType(argArray[0].Value, type1);
                }
            }
            else
            {
                throw new InvalidCastException(string.Format("from {1} to {0}", type0.Name, type1.Name));
            }
        }