// 下記のコードでは CA2115 に違反していないようだが何故？

using System;
using System.Runtime.InteropServices;

namespace Sasa.QualityTools.DrFx.Tests.Violation.CSharp.Microsoft.Security
{
    public class Rule2115 : IDisposable
    {
        private IntPtr unmanagedResource = AllocateUnmanagedResource();

        ~Rule2115()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            FreeUnmanagedResource(this.unmanagedResource);
            if (disposing)
            {
            }
        }

        public void DoSomething()
        {
            DoSomething(this.unmanagedResource);
        }

        public override string ToString()
        {
            return this.unmanagedResource.ToString();
        }
        [DllImport("native.dll")]
        internal static extern IntPtr AllocateUnmanagedResource();

        [DllImport("native.dll")]
        internal static extern IntPtr DoSomething(IntPtr unmanagedResource);

        [DllImport("native.dll")]
        internal static extern void FreeUnmanagedResource(IntPtr unmanagedResource);
    }

    //internal static partial class NativeMethods
    //{
    //    [DllImport("native.dll")]
    //    internal static extern IntPtr AllocateUnmanagedResource();

    //    [DllImport("native.dll")]
    //    internal static extern IntPtr DoSomething(IntPtr unmanagedResource);

    //    [DllImport("native.dll")]
    //    internal static extern void FreeUnmanagedResource(IntPtr unmanagedResource);
    //}
}
