Exemple #1
0
        public static object ConditionPredicate(object rtd)
        {
            RecordTypeDescriptor t = RequiresNotNull <RecordTypeDescriptor>(rtd);

            if (!t.type.IsSubclassOf(typeof(Condition)))
            {
                return(AssertionViolation("condition-predicate", "not a valid condition", rtd));
            }

            CallTarget1 p = delegate(object cond)
            {
                CallTarget1 recp = Delegate.CreateDelegate(typeof(CallTarget1), t.predicate) as CallTarget1;

                if (cond is CompoundCondition)
                {
                    CompoundCondition cc = (CompoundCondition)cond;
                    foreach (object ic in cc.conds)
                    {
                        if (IsTrue(recp(ic)))
                        {
                            return(TRUE);
                        }
                    }
                    return(FALSE);
                }
                else
                {
                    return(recp(cond));
                }
            };

            return(Closure.Create(p));
        }
Exemple #2
0
        public static object ConditionAccessor(object rtd, object proc)
        {
            RecordTypeDescriptor t = RequiresNotNull <RecordTypeDescriptor>(rtd);

            if (!t.type.IsSubclassOf(typeof(Condition)))
            {
                return(AssertionViolation("condition-accessor", "not a valid condition", rtd));
            }

            Callable c = RequiresNotNull <Callable>(proc);

            CallTarget1 p = delegate(object cond)
            {
                if (cond is CompoundCondition)
                {
                    CompoundCondition cc = (CompoundCondition)cond;
                    if (cc.conds.Length == 0)
                    {
                        // error?
                        return(FALSE);
                    }
                    else
                    {
                        foreach (object e in cc.conds)
                        {
                            if (t.type.IsInstanceOfType(e))
                            {
                                return(c.Call(e));
                            }
                        }
                        return(FALSE);
                    }
                }
                else
                {
                    if (t.type.IsInstanceOfType(cond))
                    {
                        return(c.Call(cond));
                    }
                    else
                    {
                        return(FALSE);
                    }
                }
            };

            return(Closure.Create(p));
        }