Example #1
0
        public void NullStringBehaviorCheck()
        {
            Assert.IsTrue(new LiteralString(null) == null);                    // !!
            Assert.IsTrue(new LiteralString(null).ToString() == string.Empty); // !! => ToString() never returns null;

            LiteralString s = (string)null;

            Assert.IsTrue(s == null);
            Assert.IsTrue(s.ToString().Length == 0); //!!

            s = null;                                // instead of (string)null => no implicit cast operator
            Assert.IsTrue(s == null);
            Exception caught = null;

            try{
                Assert.IsTrue(s.ToString().Length == 0);
            }
            catch (NullReferenceException ex) {
                caught = ex;
                Console.WriteLine(ex.Message);
            }
            Assert.IsNotNull(caught);
        }