Click here to Skip to main content
12,304,228 members (70,757 online)
Click here to Skip to main content
Articles » Languages » C++ / CLI » C++/CLI » Downloads


29 bookmarked

C++/CLI HowTo : Deriving from a C# disposable class

, 5 Jul 2008 CPOL
This article walks through the implementation of a C++/CLI class from a disposable C# base.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.CodeAnalysis;

namespace DisposeDemo
        MessageId = "Cs", 
        Justification = "Personal preference")]
    public class CsDisposableBase : IDisposable
        #region IDisposable Members

        public void Dispose()


        /// <summary>
        /// Derived classes need to override this appropriately
        /// </summary>
        /// <param name="disposing">Indicates whether this is a dispose call
        /// or a call invoked from the finalzier</param>
        protected virtual void Dispose(bool disposing)
            if (disposing)



        private void DisposeManagedResources()
            this.WriteLine("Disposing managed resources in base class");

        private void FreeNativeResources()
            this.WriteLine("Freeing native resources in base class");

        public CsDisposableBase(String name)
            this.Name = name;

        public String Name { get; private set; }

        protected void WriteLine(String text)
            Console.WriteLine("{0} : {1}", this.Name, text);

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nish Nishant
United States United States
Nish Nishant is a Software Architect/Consultant based out of Columbus, Ohio. He has over 16 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish is a recipient of the annual Microsoft Visual C++ MVP Award since 2002 (14 consecutive awards as of 2015).

Nish is an industry acknowledged expert in the Microsoft technology stack. He authored
C++/CLI in Action for Manning Publications in 2005, and had previously co-authored
Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on and another 250+ blog articles on his
WordPress blog. Nish is vastly experienced in team management, mentoring teams, and directing all stages of software development.

Contact Nish : You can reach Nish on his google email id voidnish.

Website and Blog

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160530.1 | Last Updated 5 Jul 2008
Article Copyright 2008 by Nish Nishant
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid