예제 #1
0
        public static void Main()
        {
            Type        classType  = typeof(BlackBoxInt);
            BlackBoxInt myInstance =
                (BlackBoxInt)Activator.CreateInstance(classType, true);

            var input = Console.ReadLine().Split('_');

            while (input[0] != "END")
            {
                var methodName = input[0];
                var value      = int.Parse(input[1]);

                classType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic)
                .Invoke(myInstance, new object[] { value });

                var fieldInnerValue = classType
                                      .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                      .First()
                                      .GetValue(myInstance);

                Console.WriteLine(fieldInnerValue);

                input = Console.ReadLine().Split('_');
            }
        }
예제 #2
0
        public static void Main()
        {
            Type        blackBoxType = typeof(BlackBoxInt);
            BlackBoxInt myBlackBox   = (BlackBoxInt)Activator.CreateInstance(blackBoxType, true);

            string inputLine;

            while ((inputLine = Console.ReadLine()) != "END")
            {
                string[] tokens     = inputLine.Split('_');
                string   methodName = tokens[0];
                int      value      = int.Parse(tokens[1]);

                blackBoxType.GetMethod(methodName, NonPulbicFlags)
                .Invoke(myBlackBox, new object[] { value });

                object innerStateValue = blackBoxType
                                         .GetFields(NonPulbicFlags)
                                         .First()
                                         .GetValue(myBlackBox);

                Console.WriteLine(innerStateValue);
            }
        }