void Test(bool b)
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType()/*abcd*/.IsAssignableFrom(expr2.GetType() /*efgh*/)) //Noncompliant {{Use the "IsInstanceOfType()" method instead.}}
//              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            { }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            { }

            if (!typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(expr1.GetType())) //Noncompliant {{Use the "is" operator instead.}}
            { }
            var x = typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(expr1.GetType()); //Noncompliant
            if (expr1 is GetTypeWithIsAssignableFrom) // Noncompliant  {{Use a "null" check instead.}}
//              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            { }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            { }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();
            if (t1.IsAssignableFrom(t2)) //Compliant
            { }
            if (t1.IsAssignableFrom(c: expr2.GetType())) //Noncompliant
            { }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            { }

            Test(t1.IsAssignableFrom(c: expr2.GetType())); //Noncompliant
        }
        void Test(bool b)
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType()/*abcd*/.IsAssignableFrom(expr2.GetType() /*efgh*/)) //Noncompliant
            { }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            { }

            if (!typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(expr1.GetType())) //Noncompliant
            { }
            var x = typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(expr1.GetType()); //Noncompliant
            if (expr1 is GetTypeWithIsAssignableFrom) //Compliant
            { }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            { }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();
            if (t1.IsAssignableFrom(t2)) //Compliant
            { }
            if (t1.IsAssignableFrom(c: expr2.GetType())) //Noncompliant
            { }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            { }

            Test(t1.IsAssignableFrom(c: expr2.GetType())); //Noncompliant
        }
        void Test(bool b)
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType()/*abcd*/.IsInstanceOfType(expr2 /*efgh*/)) //Fixed
            { }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            { }

            if (!(expr1 is GetTypeWithIsAssignableFrom)) //Fixed
            { }
            var x = expr1 is GetTypeWithIsAssignableFrom; //Fixed
            if (expr1 != null) // Fixed
            { }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            { }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();
            if (t1.IsAssignableFrom(t2)) //Compliant
            { }
            if (t1.IsInstanceOfType(expr2)) //Fixed
            { }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            { }

            Test(t1.IsInstanceOfType(expr2)); //Fixed
        }
        void Test()
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType().IsAssignableFrom(expr2.GetType())) //Noncompliant
            { }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            { }

            if (expr1.GetType().IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Noncompliant
            { }
            if (expr1 is GetTypeWithIsAssignableFrom) //Compliant
            { }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            { }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();
            if (t1.IsAssignableFrom(t2)) //Compliant
            { }
            if (t1.IsAssignableFrom(expr2.GetType())) //Noncompliant
            { }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            { }
        }
        void Test(bool b)
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType() /*abcd*/.IsAssignableFrom(expr2.GetType() /*efgh*/)) //Noncompliant {{Use the 'IsInstanceOfType()' method instead.}}
//              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            {
            }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            {
            }

            if (!typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(expr1.GetType())) //Noncompliant {{Use the 'is' operator instead.}}
            {
            }
            var x = typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(expr1.GetType()); //Noncompliant

            if (expr1 is GetTypeWithIsAssignableFrom)                                      // Noncompliant  {{Use a 'null' check instead.}}
//              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            {
            }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();

            if (t1.IsAssignableFrom(t2)) //Compliant
            {
            }
            if (t1.IsAssignableFrom(c: expr2.GetType())) //Noncompliant
            {
            }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            Test(t1.IsAssignableFrom(c: expr2.GetType())); //Noncompliant

            if (expr1 is object)                           // Compliant - "is object" is a commonly used pattern for non-null check
            {
            }

            if (expr1 is System.Object) // Compliant - "is object" is a commonly used pattern for non-null check
            {
            }
        }
示例#6
0
        void Test(bool b)
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType() /*abcd*/.IsInstanceOfType(expr2 /*efgh*/)) //Fixed
            {
            }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            {
            }

            if (!(expr1 != null)) //Fixed
            {
            }
            var x = expr1 != null; //Fixed

            if (expr1 != null)     // Fixed
            {
            }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();

            if (t1.IsAssignableFrom(t2)) //Compliant
            {
            }
            if (t1.IsInstanceOfType(expr2)) //Fixed
            {
            }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            Test(t1.IsInstanceOfType(expr2)); //Fixed

            if (expr1 is object)              // Compliant - "is object" is a commonly used pattern for non-null check
            {
            }

            if (expr1 is System.Object) // Compliant - "is object" is a commonly used pattern for non-null check
            {
            }
        }
        void Test(bool b)
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType() /*abcd*/.IsAssignableFrom(expr2.GetType() /*efgh*/)) //Noncompliant {{Use the "IsInstanceOfType()" method instead.}}
//              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            {
            }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            {
            }

            if (!typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(expr1.GetType())) //Noncompliant {{Use the "is" operator instead.}}
            {
            }
            var x = typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(expr1.GetType()); //Noncompliant

            if (expr1 is GetTypeWithIsAssignableFrom)                                      // Noncompliant  {{Use a "null" check instead.}}
//              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            {
            }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();

            if (t1.IsAssignableFrom(t2)) //Compliant
            {
            }
            if (t1.IsAssignableFrom(c: expr2.GetType())) //Noncompliant
            {
            }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            Test(t1.IsAssignableFrom(c: expr2.GetType())); //Noncompliant
        }
        void Test(bool b)
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType() /*abcd*/.IsInstanceOfType(expr2 /*efgh*/)) //Fixed
            {
            }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            {
            }

            if (!(expr1 != null)) //Fixed
            {
            }
            var x = expr1 != null; //Fixed

            if (expr1 != null)     // Fixed
            {
            }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();

            if (t1.IsAssignableFrom(t2)) //Compliant
            {
            }
            if (t1.IsInstanceOfType(expr2)) //Fixed
            {
            }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            Test(t1.IsInstanceOfType(expr2)); //Fixed
        }
        void Test(bool b)
        {
            var expr1 = new GetTypeWithIsAssignableFrom();
            var expr2 = new GetTypeWithIsAssignableFrom();

            if (expr1.GetType() /*abcd*/.IsAssignableFrom(expr2.GetType() /*efgh*/)) //Noncompliant
            {
            }
            if (expr1.GetType().IsInstanceOfType(expr2)) //Compliant
            {
            }

            if (expr1.GetType().IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Noncompliant
            {
            }
            if (expr1 is GetTypeWithIsAssignableFrom) //Compliant
            {
            }

            if (typeof(GetTypeWithIsAssignableFrom).IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            var t1 = expr1.GetType();
            var t2 = expr2.GetType();

            if (t1.IsAssignableFrom(t2)) //Compliant
            {
            }
            if (t1.IsAssignableFrom(c: expr2.GetType())) //Noncompliant
            {
            }

            if (t1.IsAssignableFrom(typeof(GetTypeWithIsAssignableFrom))) //Compliant
            {
            }

            Test(t1.IsAssignableFrom(c: expr2.GetType())); //Noncompliant
        }