Пример #1
0
        private string GetInvocationListFlag(identify_null start, identify_null working)
        {
            DelegateCombine1 delctor      = new DelegateCombine1();
            TestClass        testinstance = new TestClass();

            string sFlag = string.Empty;

            if (start == identify_null.c_Start_null_false)
            {
                delctor.starkWork = new booldelegate(testinstance.StartWork_Bool);
            }
            else
            {
                delctor.starkWork = null;
            }
            if (working == identify_null.c_Working_null_false)
            {
                delctor.working = new booldelegate(testinstance.Working_Bool);
            }
            else
            {
                delctor.working = null;
            }
            booldelegate combine = (booldelegate)Delegate.Combine(delctor.starkWork, delctor.working);

            if (combine == null)
            {
                return(string.Empty);
            }

            for (IEnumerator itr = combine.GetInvocationList().GetEnumerator(); itr.MoveNext();)
            {
                booldelegate bd = (booldelegate)itr.Current;
                if (bd.Equals(delctor.starkWork))
                {
                    sFlag += c_StartWrok;
                }
                if (bd.Equals(delctor.working))
                {
                    sFlag += c_Working;
                }
            }
            combine();
            return(sFlag);
        }
Пример #2
0
        private bool CombineImpl(booldelegate delegatesrc, identify_null start)
        {
            DelegateCombineImpl delctor      = new DelegateCombineImpl();
            TestClass           testinstance = new TestClass();

            string       sFlag       = string.Empty;
            string       sFlagAdd    = string.Empty;
            booldelegate combineImpl = delegatesrc;

            if (start == identify_null.c_Start_null_false)
            {
                delctor.starkWork = new booldelegate(testinstance.StartWork_Bool);
                combineImpl      += (booldelegate)delctor.starkWork;
                sFlagAdd          = c_StartWork;
            }
            else if (start == identify_null.c_Start_null_false_duplicate)
            {
                delctor.starkWork = new booldelegate(testinstance.StartWork_Bool);
                combineImpl      += (booldelegate)delctor.starkWork;
                sFlagAdd          = c_StartWork;
                //The invocation list can contain duplicate entries; that is, entries that refer to the same method on the same object.
                combineImpl += (booldelegate)delctor.starkWork;
                sFlagAdd    += sFlagAdd;
            }
            else if (start == identify_null.c_Start_null_true)
            {
                delctor.starkWork = null;
                combineImpl      += (booldelegate)delctor.starkWork;
            }
            else if (start == identify_null.c_Working_null_false)
            {
                delctor.working = new booldelegate(testinstance.Working_Bool);
                combineImpl    += (booldelegate)delctor.working;
                sFlagAdd        = c_Working;
            }
            else
            {
                delctor.working = null;
                combineImpl    += (booldelegate)delctor.working;
            }

            if (combineImpl == null)
            {
                return(true);
            }

            for (IEnumerator itr = combineImpl.GetInvocationList().GetEnumerator(); itr.MoveNext();)
            {
                booldelegate bd = (booldelegate)itr.Current;
                //the filter is to get the delegate which is appended through equals method.
                if (bd.Equals(delctor.starkWork))
                {
                    sFlag += c_StartWork;
                }
                if (bd.Equals(delctor.working))
                {
                    sFlag += c_Working;
                }
            }
            combineImpl();
            //judge delegate is appended  to the end of the invocation list of the current
            if (sFlag == sFlagAdd)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }