示例#1
0
		public BELArray Collect(ExecutionContext ctx, Block block)
		{
			BELArray answer = new BELArray();
			
			foreach (IBELObject each in Array)
			{
				ArrayList parms = new ArrayList();
				parms.Add(each);
				answer.Add(block.Value(ctx, parms));
			}
			return answer;
		}
示例#2
0
		public BELArray Select(ExecutionContext ctx, Block block)
		{
			BELArray answer = new BELArray();
			
			foreach (IBELObject each in Array)
			{
				ArrayList parms = new ArrayList();
				parms.Add(each);
				IBELObject objValue = block.Value(ctx, parms);
				BELBoolean test = objValue as BELBoolean;
				if (test == null)
					throw new ExecutionException("Select block must evaluate to a boolean.  Got " + BELType.BELTypeForType(objValue.GetType()).ExternalTypeName + " instead.");
				if (test.Value)
					answer.Add(each);
			}
			return answer;
		}
示例#3
0
		public IBELObject IfNotNullElse(ExecutionContext ctx, Block notNullBlock, Block nullBlock)
		{
			return nullBlock.Value(ctx);
		}
示例#4
0
		public IBELObject IfNull(ExecutionContext ctx, Block block)
		{
			return block.Value(ctx);
		}
示例#5
0
        public BELArray SortBy(ExecutionContext ctx, Block block)
        {
            // This code formerly sorted the list by having the IComparer do the comparison.
            // This was resulting in lots of superficial comparisons, as the block was being
            // evaluated lots of extra times - for the left and the right item on every comparison.
            // Instead, I changed it to rip through the array, evaluate the block exaclty once
            // for each item, and then do the sort on just the values.
            List<BelArrayEntry> entries = new List<BelArrayEntry>();

            try
            {
                foreach (IBELObject entry in Array)
                {
                    ArrayList a1 = new ArrayList();
                    a1.Add(entry);
                    IBELObject value = block.Value(ctx, a1);

                    IComparable comparable = value as IComparable;
                    if (comparable == null)
                    {
                        throw new ExecutionException(null, "Can not compare objects of type " + BELType.ExternalTypeNameForType(value.GetType()));
                    }

                    entries.Add(new BelArrayEntry(entry, comparable));
                }

                entries.Sort(new BelArrayEntry.Comparer());

            }
            catch (InvalidOperationException e)
            {
                throw e.InnerException;
            }

            BELArray results = new BELArray();
            foreach (BelArrayEntry entry in entries)
            {
                results.Add(entry.Entry);
            }
            return results;
        }
示例#6
0
 public IBELObject IfFalse(ExecutionContext ctx, Block block)
 {
     if (!Value)
         return block.Value(ctx);
     else
         return UndefinedObject.Instance;
 }
示例#7
0
 public IBELObject IfTrueIfFalse(ExecutionContext ctx, Block trueBlock, Block falseBlock)
 {
     if (Value)
         return trueBlock.Value(ctx);
     else
         return falseBlock.Value(ctx);
 }