public override CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right)
        {
            if (left.GetObject() is DeleEvent)
            {
                DeleEvent info     = left.GetObject() as DeleEvent;
                Delegate  calldele = null;

                //!--exist bug.

                /*if (right.value is DeleFunction) calldele = CreateDelegate(right.value as DeleFunction);
                 * else if (right.value is DeleLambda) calldele = CreateDelegate(right.value as DeleLambda);
                 * else if (right.value is Delegate) calldele = right.value as Delegate;*/

                object rightValue = right.GetObject();
                if (rightValue is DeleFunction)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(rightValue as DeleFunction);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(rightValue as DeleFunction);
                    }
                }
                else if (rightValue is DeleLambda)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(rightValue as DeleLambda);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(rightValue as DeleLambda);
                    }
                }
                else if (rightValue is Delegate)
                {
                    calldele = rightValue as Delegate;
                }

                if (code == '+')
                {
                    info._event.AddEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Map(rightValue as IDeleBase, calldele);
                    //}
                    CQ_Value ret = new CQ_Value();//type保持null
                    ret.SetNoneTypeObject(info);
                    return(ret);
                }
                else if (code == '-')
                {
                    info._event.RemoveEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Destroy(rightValue as IDeleBase);
                    //}
                    CQ_Value ret = new CQ_Value();//type保持null
                    ret.SetNoneTypeObject(info);
                    return(ret);
                }
            }
            else if (left.GetObject() is Delegate || left.GetObject() == null)
            {
                Delegate info     = left.GetObject() as Delegate;
                Delegate calldele = null;
                if (right.GetObject() is DeleFunction)
                {
                    calldele = CreateDelegate(right.GetObject() as DeleFunction);
                }
                else if (right.GetObject() is DeleLambda)
                {
                    calldele = CreateDelegate(right.GetObject() as DeleLambda);
                }
                else if (right.GetObject() is Delegate)
                {
                    calldele = right.GetObject() as Delegate;
                }
                if (code == '+')
                {
                    CQ_Value ret = new CQ_Value();//type保持null
                    ret.SetNoneTypeObject(Delegate.Combine(info, calldele));
                    return(ret);
                }
                else if (code == '-')
                {
                    CQ_Value ret = new CQ_Value();//type保持null
                    ret.SetNoneTypeObject(Delegate.Remove(info, calldele));
                    return(ret);
                }
            }
            throw new NotSupportedException();
        }
Example #2
0
        public override object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
        {
            returntype = null;

            if (left is DeleEvent)
            {
                DeleEvent info     = left as DeleEvent;
                Delegate  calldele = null;

                //!--exist bug.

                /*if (right.value is DeleFunction) calldele = CreateDelegate(right.value as DeleFunction);
                 * else if (right.value is DeleLambda) calldele = CreateDelegate(right.value as DeleLambda);
                 * else if (right.value is Delegate) calldele = right.value as Delegate;*/

                object rightValue = right.value;
                if (rightValue is DeleFunction)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(rightValue as DeleFunction);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(rightValue as DeleFunction);
                    }
                }
                else if (rightValue is DeleLambda)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(rightValue as DeleLambda);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(rightValue as DeleLambda);
                    }
                }
                else if (rightValue is Delegate)
                {
                    calldele = rightValue as Delegate;
                }

                if (code == '+')
                {
                    info._event.AddEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Map(rightValue as IDeleBase, calldele);
                    //}
                    return(info);
                }
                else if (code == '-')
                {
                    info._event.RemoveEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Destroy(rightValue as IDeleBase);
                    //}
                    return(info);
                }
            }
            else if (left is Delegate || left == null)
            {
                Delegate info     = left as Delegate;
                Delegate calldele = null;
                if (right.value is DeleFunction)
                {
                    calldele = CreateDelegate(right.value as DeleFunction);
                }
                else if (right.value is DeleLambda)
                {
                    calldele = CreateDelegate(right.value as DeleLambda);
                }
                else if (right.value is Delegate)
                {
                    calldele = right.value as Delegate;
                }
                if (code == '+')
                {
                    return(Delegate.Combine(info, calldele));;
                }
                else if (code == '-')
                {
                    return(Delegate.Remove(info, calldele));
                }
            }
            return(new NotSupportedException());
        }