コード例 #1
0
 public override Value Execute(Args args, Environment environment, SourcePos pos)
 {
     return(ValueBoolean.From(args.Get("obj").IsNull()));
 }
コード例 #2
0
 public override Value Execute(Args args, Environment environment, SourcePos pos)
 {
     return(args.GetAsInt("obj"));
 }
コード例 #3
0
ファイル: FuncSum.cs プロジェクト: damianbrunold/checkerlang
        public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            if (args.IsNull("list"))
            {
                return(ValueNull.NULL);
            }

            var list   = args.GetList("list").GetValue();
            var ignore = new List <Value>();

            if (args.HasArg("ignore"))
            {
                ignore.AddRange(args.GetList("ignore").GetValue());
            }

            var resultdecimal   = (decimal)0;
            var resultint       = 0L;
            var decimalrequired = false;

            foreach (var value in list)
            {
                var skipvalue = false;
                foreach (var ignoreval in ignore)
                {
                    if (ignoreval.IsEquals(value))
                    {
                        skipvalue = true;
                        break;
                    }
                }
                if (skipvalue)
                {
                    continue;
                }

                if (decimalrequired)
                {
                    resultdecimal += value.AsDecimal().GetValue();
                }
                else if (value.IsInt())
                {
                    resultint += value.AsInt().GetValue();
                }
                else if (value.IsDecimal())
                {
                    if (!decimalrequired)
                    {
                        decimalrequired = true;
                        resultdecimal   = resultint;
                    }

                    resultdecimal += value.AsDecimal().GetValue();
                }
                else
                {
                    throw new ControlErrorException(new ValueString("ERROR"), "Cannot sum " + value, pos);
                }
            }

            if (decimalrequired)
            {
                return(new ValueDecimal(resultdecimal));
            }
            return(new ValueInt(resultint));
        }