using System;
using System.Runtime.InteropServices;

namespace Sasa.QualityTools.DrFx.Tests.Violation.CSharp.Microsoft.Usage
{
    // このクラスは CA2216 に違反しています。
    public class Rule2216 : IDisposable
    {
        private IntPtr unmanagedResource = NativeMethods.AllocateUnmanagedResource();

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

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

        public override string ToString()
        {
            return this.unmanagedResource.ToString();
        }
    }

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

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