コード例 #1
0
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: Verify dispose interface is implemented in customer class...");

        try
        {
            int        i     = TestLibrary.Generator.GetInt32(-55);
            IntPtr     ip    = new IntPtr(i);
            MyResource myRes = new MyResource(ip);

            myRes.Dispose();

            if (myRes.handle != IntPtr.Zero)
            {
                TestLibrary.TestFramework.LogError("004", "The handle should be IntPtr.zero!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005", "Unexpected exception occurs: " + e);
            retVal = false;
        }

        return(retVal);
    }
コード例 #2
0
        public static void DemoDispose()
        {
            using (var res = new MyResource())
            {
                Console.WriteLine("Verwende MyResource");
            }

            // Gleichbedeutend zu:
            MyResource res2 = new MyResource();

            try
            {
                Console.WriteLine("Verwende MyResource");
            }
            finally
            {
                if (res2 != null)
                {
                    res2.Dispose();
                }
            }
        }
コード例 #3
0
    public bool PosTest3()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest3: Verify dispose interface is implemented in customer class...");

        try
        {
            int i = TestLibrary.Generator.GetInt32(-55);
            IntPtr ip = new IntPtr(i);
            MyResource myRes = new MyResource(ip);

            myRes.Dispose();

            if (myRes.handle != IntPtr.Zero)
            {
                TestLibrary.TestFramework.LogError("004","The handle should be IntPtr.zero!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005","Unexpected exception occurs: " + e);
            retVal = false;
        }

        return retVal;
    }