예제 #1
0
        public void GetData_Pass_Object_Good()
        {
            var getter = new DataGetter();
            var data = new DataHolder() { Multipler = 1 };

            getter.NewData += (e) =>
            {
                // This simulates situation where something else changes public property
                if (e > 2)
                    data.Multipler = 4;

                Trace.WriteLine(Extensions.TraceMessage(e.ToString()));
            };

            getter.Ready += (s, e) =>
            {
                stopFlag.Set();
            };

            getter.GetData_Good(data);

            stopFlag.WaitOne();
        }
예제 #2
0
        public void GetData_Pass_ReferenceType_Bad()
        {
            var getter = new DataGetter();
            getter.DataHolder = new DataHolder() { Multipler = 1 };
            getter.NewData += (e) =>
            {
                // This simulates situation where something else changes public property
                if (e > 2)
                    getter.DataHolder.Multipler = 4;

                Trace.WriteLine(Extensions.TraceMessage(e.ToString()));
            };

            getter.Ready += (s, e) =>
            {
                stopFlag.Set();
            };

            getter.GetData_With_ReferenceType();

            stopFlag.WaitOne();
        }
예제 #3
0
        public void GetData_Use_PublicVariable_Bad()
        {
            var getter = new DataGetter();

            getter.NewData += (e) =>
            {
                // This simulates situatin where something else changes public property
                if (e > 2)
                    getter.Multiplier = 4;

                Trace.WriteLine(Extensions.TraceMessage(e.ToString()));
            };

            getter.Ready += (s, e) =>
            {
                stopFlag.Set();
            };

            getter.GetData();

            stopFlag.WaitOne();
        }