public RedundantToStringCall()
        {
            var s = "foo";
            var t = "fee fie foe " + s.ToString();  // Noncompliant {{There's no need to call 'ToString()' on a string.}}

//                                    ^^^^^^^^^^^
            t = "fee fie foe " + s.ToString(System.Globalization.CultureInfo.InvariantCulture);
            var u = "" + 1.ToString();        // Compliant, value type

            u = new object().ToString() + ""; // Noncompliant
            u = new object().ToString()       // Noncompliant
                + new object().ToString();    // Noncompliant, note: this is why we don't have a global fix

            u += new object().ToString();     // Noncompliant {{There's no need to call 'ToString()', the compiler will do it for you.}}
            u  = 1.ToString() + 2;

            var x = 1 + 3;

            var v = string.Format("{0}",
                                  new object().ToString()); //Noncompliant

            v = string.Format("{0}",
                              1.ToString()); // Compliant, value type

            u = 1.ToString();

            var m = new MyClass();

            s = m.ToString() + "";

            s = base.ToString() + "";
        }
        public RedundantToStringCall()
        {
            var s = "foo";
            var t = "fee fie foe " + s.ToString();  // Noncompliant
            t = "fee fie foe " + s.ToString(System.Globalization.CultureInfo.InvariantCulture);
            var u = "" + 1.ToString(); //Noncompliant
            u = 1.ToString() + ""; // Noncompliant
            u = 1.ToString() // Noncompliant
                + 2.ToString(); // Noncompliant, note: this is why we don't have a global fix

            u += 2.ToString(); // Noncompliant
            u = 1.ToString() + 2;

            var x = 1 + 3;

            var v = string.Format("{0}",
                1.ToString()); //Noncompliant

            u = 1.ToString();

            var m = new MyClass();
            s = m.ToString() + "";

            s = base.ToString() + "";
        }
Esempio n. 3
0
        public RedundantToStringCall()
        {
            var s = "foo";
            var t = "fee fie foe " + s;  // Fixed

            t = "fee fie foe " + s.ToString(System.Globalization.CultureInfo.InvariantCulture);
            var u = "" + 1.ToString();     // Compliant, value type

            u = new object() + "";         // Fixed
            u = new object()               // Fixed
                + new object().ToString(); // Fixed

            u += new object();             // Fixed
            u  = 1.ToString() + 2;

            var x = 1 + 3;

            var v = string.Format("{0}",
                                  new object()); //Fixed

            v = string.Format("{0}",
                              1.ToString()); // Compliant, value type

            u = 1.ToString();

            var m = new MyClass();

            s = m.ToString() + "";

            s = base.ToString() + "";
        }
        public RedundantToStringCall()
        {
            var s = "foo";
            var t = "fee fie foe " + s;  // Fixed
            t = "fee fie foe " + s.ToString(System.Globalization.CultureInfo.InvariantCulture);
            var u = "" + 1.ToString(); // Compliant, value type
            u = new object() + ""; // Fixed
            u = new object() // Fixed
                + new object().ToString(); // Fixed

            u += new object(); // Fixed
            u = 1.ToString() + 2;

            var x = 1 + 3;

            var v = string.Format("{0}",
                new object()); //Fixed

            v = string.Format("{0}",
                1.ToString()); // Compliant, value type

            u = 1.ToString();

            var m = new MyClass();
            s = m.ToString() + "";

            s = base.ToString() + "";
        }
        public RedundantToStringCall()
        {
            var s = "foo";
            var t = "fee fie foe " + s.ToString();  // Noncompliant {{There's no need to call "ToString()" on a string.}}
//                                    ^^^^^^^^^^^
            t = "fee fie foe " + s.ToString(System.Globalization.CultureInfo.InvariantCulture);
            var u = "" + 1.ToString(); // Compliant, value type
            u = new object().ToString() + ""; // Noncompliant
            u = new object().ToString() // Noncompliant
                + new object().ToString(); // Noncompliant, note: this is why we don't have a global fix

            u += new object().ToString(); // Noncompliant {{There's no need to call "ToString()", the compiler will do it for you.}}
            u = 1.ToString() + 2;

            var x = 1 + 3;

            var v = string.Format("{0}",
                new object().ToString()); //Noncompliant

            v = string.Format("{0}",
                1.ToString()); // Compliant, value type

            u = 1.ToString();

            var m = new MyClass();
            s = m.ToString() + "";

            s = base.ToString() + "";
        }
Esempio n. 6
0
        static void MultiplePop()
        {
            MyClass o = null;

            o = new MyClass
            {
                MyProperty = ""
            };
            o.ToString(); // Compliant
        }