Example #1
0
        static void Main(string[] args)
        {
            var demo = new AccessDemo();
            var bad  = new BadClass();

            bad.Age  = 150;
            bad._age = 150;
            //bad._ssn;

            demo.PublicDemo();
        }
Example #2
0
        static void Main(string[] args)
        {
            AccessDemo demo = new AccessDemo();

            //demo.

            BadClass bad = new BadClass();

            bad.Age  = 150;
            bad._age = 150;

            demo.PublicDemo();
        }
        static void Main(string[] args)
        {
            AccessDemo demo = new AccessDemo();

            demo.PublicDemo(); //will call just the public method

            BadClass bad = new BadClass();

            //bad.creditCardNumber
            //bad.SSN
            //bad._ssn
            bad.Age  = 150;
            bad._age = 150;
        }
Example #4
0
        private void btnBadPayload_Click(object sender, EventArgs ea)
        {
            var client = new JokeContractClient(cbo.Text);

            try
            {
                var bad = new BadClass();
                bad.Click += btnBadMsg_Click;
                var echoed = client.ObjectWork(bad);
                Text = echoed.ToString();
            }
            catch (Exception e)
            {
                Text = e.ToMessageWithType();
            }

            client.Dispose();
        }
        public Program()
        {
            Reroute console = new Reroute(this);

            try {
                console.Compile("Good Class");

                GoodClass gc = new GoodClass(this);

                console.Compile("Bad Class");

                BadClass bc = new BadClass(this);

                console.Report();
            }
            catch (Exception e) {
                console.Cancel(e.Message);
            }
        }
Example #6
0
    private static void CatchWithNoException()
    {
        Console.Out.WriteLine("CatchWithNoException called.");

        try
        {
            Console.Out.WriteLine("In try block...");
            var badClass = new BadClass();
            badClass.BadMethod();
            Console.Out.WriteLine("BadMethod called.");
        }
        catch
        {
            Console.Out.WriteLine("Catch entered.");
        }
        finally
        {
            Console.Out.WriteLine("Finally entered.");
        }
    }
Example #7
0
    private static void CatchException()
    {
        Console.Out.WriteLine("CatchException called.");

        try
        {
            Console.Out.WriteLine("In try block...");
            var badClass = new BadClass();
            badClass.BadMethod();
            Console.Out.WriteLine("BadMethod called.");
        }
        catch (Exception exception)
        {
            Console.Out.WriteLine($"Catch entered - exception type is {exception.GetType().FullName}");
        }
        finally
        {
            Console.Out.WriteLine("Finally entered.");
        }
    }
        static void Main(string[] args)
        {
            AccessDemo demo = new AccessDemo();

            // demo. here shows a much reduced list of available options making things much clearer what can and can't be invoked.

            // PrivateDemo is not visible in this project!

            // Internal demo is not accessible here either as this is a different project/assembly

            demo.PublicDemo(); // Public as expected can be accessed here when it's in a different assembly.

            BadClass bad = new BadClass();

            bad.creditCardNumber = "123456"; // This should never be done - information leakage with no protection to the property!

            Console.WriteLine(bad.SSN);      // Good practice as this will show the filtered property - if _ssn was public we could inadvertently expose information that should be private.

            bad.Age = 150;                   // Will in effect do nothing anbd be rejected. If we could get to _age then that property loses its protection and validation

            SayHello();                      // Can invoke a private method within the same class.
        }
Example #9
0
        private void btnBadPayload_Click(object sender, EventArgs ea)
        {
          var client = new JokeContractClient(cbo.Text);

          try
          {
            var bad = new BadClass();
            bad.Click += btnBadMsg_Click;
            var echoed = client.ObjectWork(bad);
            Text = echoed.ToString();
          }
          catch (Exception e)
          {
            Text = e.ToMessageWithType();
          }

          client.Dispose();
        }