static void Main()
        {
            var myclass1 = new MyClass1();
            var x        = (IMyInterface)myclass1; // Noncompliant

//                   ^^^^^^^^^^^^
            x = myclass1 as IMyInterface;
            bool b = myclass1 is IMyInterface;

            var arr  = new MyClass1[10];
            var arr2 = (IMyInterface[])arr;

            var myclass2 = new MyClass2();
            var y        = (IMyInterface)myclass2;

            IMyInterface  i  = new MyClass3();
            var           c  = (IMyInterface2)i; // Compliant
            IMyInterface4 ii = null;
            var           c  = (IMyInterface2)i; // Compliant
            var           d  = (IMyInterface3)i;

            var o = (object)true;

            d = (IMyInterface3)o;

            var coll = (IEnumerable <int>) new List <int>();

            var z = (IDisposable) new MyClass4();

            var w = (IDisposable)(new Node());
        }
        static void Main()
        {
            var myclass1 = new MyClass1();
            var x = (IMyInterface)myclass1; // Noncompliant
//                   ^^^^^^^^^^^^
            x = myclass1 as IMyInterface; // Noncompliant
//                          ^^^^^^^^^^^^
            bool b = myclass1 is IMyInterface; // Noncompliant {{Review this cast; in this project there's no type that extends "MyClass1" and implements "IMyInterface".}}

            var arr = new MyClass1[10];
            var arr2 = (IMyInterface[])arr;

            var myclass2 = new MyClass2();
            var y = (IMyInterface)myclass2;

            IMyInterface i = new MyClass3();
            var c = (IMyInterface2)i; // Compliant
            IMyInterface4 ii = null;
            var c = (IMyInterface2)i; // Compliant
            var d = (IMyInterface3)i;

            var o = (object)true;
            d = (IMyInterface3)o;

            var coll = (IEnumerable<int>)new List<int>();

            var z = (IDisposable)new MyClass4();

            var w = (IDisposable)(new Node());
        }
Example #3
0
        static void Main()
        {
            var myclass1 = new MyClass1();
            var x        = (IMyInterface)myclass1; // Noncompliant

//                   ^^^^^^^^^^^^
            x = myclass1 as IMyInterface;      // Noncompliant
//                          ^^^^^^^^^^^^
            bool b = myclass1 is IMyInterface; // Noncompliant {{Review this cast; in this project there's no type that extends 'MyClass1' and implements 'IMyInterface'.}}

            var arr  = new MyClass1[10];
            var arr2 = (IMyInterface[])arr;

            var myclass2 = new MyClass2();
            var y        = (IMyInterface)myclass2;

            IMyInterface  i  = new MyClass3();
            var           c  = (IMyInterface2)i; // Compliant
            IMyInterface4 ii = null;
            var           c  = (IMyInterface2)i; // Compliant
            var           d  = (IMyInterface3)i;

            var o = (object)true;

            d = (IMyInterface3)o;

            var coll = (IEnumerable <int>) new List <int>();

            var z = (IDisposable) new MyClass4();

            var w = (IDisposable)(new Node());
        }
        static void Main()
        {
            var myclass1 = new MyClass1();
            var x = (IMyInterface)myclass1; // Noncompliant
            x = myclass1 as IMyInterface; // Noncompliant
            bool b = myclass1 is IMyInterface; // Noncompliant

            var arr = new MyClass1[10];
            var arr2 = (IMyInterface[])arr;

            var myclass2 = new MyClass2();
            var y = (IMyInterface)myclass2;

            IMyInterface i = new MyClass3();
            var c = (IMyInterface2)i; // Compliant
            IMyInterface4 ii = null;
            var c = (IMyInterface2)i; // Compliant
            var d = (IMyInterface3)i;

            var o = (object)true;
            d = (IMyInterface3)o;

            var coll = (IEnumerable<int>)new List<int>();

            var z = (IDisposable)new MyClass4();

            var w = (IDisposable)(new Node());
        }
        static void EntryPoint(IMyInterface interfaceRef)
        {
            MyClass1 class1      = (MyClass1)interfaceRef; // Noncompliant
            int      privateData = class1.Data;

            class1 = interfaceRef as MyClass1;  // Noncompliant
            if (class1 != null)
            {
                // ...
            }

            var interf = (IMyInterface2)interfaceRef;

            interf = (IMyInterface2)class1;
            var o = (object)interfaceRef;
        }
Example #6
0
        static void EntryPoint(IMyInterface interfaceRef)
        {
            MyClass1 class1 = (MyClass1)interfaceRef;  // Noncompliant {{Remove this cast and edit the interface to add the missing functionality.}}
//                            ^^^^^^^^^^^^^^^^^^^^^^
            int privateData = class1.Data;

            class1 = interfaceRef as MyClass1;  // Noncompliant
//                   ^^^^^^^^^^^^^^^^^^^^^^^^
            if (class1 != null)
            {
                // ...
            }

            var interf = (IMyInterface2)interfaceRef;

            interf = (IMyInterface2)class1;
            var o = (object)interfaceRef;
        }