Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6641507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:49:09+00:00 2026-05-25T23:49:09+00:00

I have got below code in C# 2.0 and I am trying to implement

  • 0

I have got below code in C# 2.0 and I am trying to implement IDisposable in my class.

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using Tridion.ContentManager;
using Tridion.ContentManager.Templating.Assembly;
using Tridion.ContentManager.Templating;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.ContentManagement.Fields;
using Emirates.Tridion.BuildingBlocks.Base;
using th = my.Tridion.BuildingBlocks.Base.TemplateHelper;
using ut = my.Tridion.BuildingBlocks.Base.Utilities;
using tc = Tridion.ContentManager.CommunicationManagement;
using System.IO;
using System.Globalization;
using System.Threading;

namespace my.BuildingBlocks.Utilities
{

    [TcmTemplateTitle("Page Metadata Values")]
    public class PageMetaDataValues : TemplateBase, IDisposable
    {

        private bool m_Disposed = false;

        protected bool Disposed
        {
            get
            {
                lock (this)
                {
                    return (m_Disposed);
                }
            }
        }


        public override void Transform(Engine engine, Package package)
        {
            Initialize(engine, package);
            m_Logger.Info("Start of Page Metadata Values");
            tc.Publication pubObject= m_Engine.GetSession().GetObject(m_Publication.Id) as tc.Publication;          
            if (pubObject != null)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(ut.RenderPageLocale(pubObject));
            }
            package.PushItem("PageMetaDataValues", package.CreateStringItem(ContentType.Xml, RenderCurrentPageXML()));
            m_Logger.Info("End of Page Metadata Values");
        }

        private string RenderCurrentPageXML()
        {
            m_Logger.Info("Rendering the Page Metadata Values");

            XmlDocument pageDoc = new XmlDocument();
            pageDoc.LoadXml(GetCurrentPageXML(m_Page.Id));
            return pageDoc.InnerXml;
        }      

        void IDisposable.Dispose
        {   
            get
            {
                lock (this)
                {
                    if (m_Disposed == false)
                    {
                        Cleanup();
                        m_Disposed = true;
                        GC.SuppressFinalize(this);
                    }
                }
            }

        }
        protected virtual void Cleanup()
        {
            /* do cleanup of unmanaged resources here */
        }
        #endregion

    }
}   

Please suggest whether I have implemnted IDisposable interface correclty or I need to do some code changes above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:49:10+00:00Added an answer on May 25, 2026 at 11:49 pm

    That’s not the normal IDisposable pattern, typically you’d do something more like:

    public class DisposableClass : IDisposable
    {
        ~DisposableClass()
        {
            Dispose(false);
        }
    
        private bool disposed = false;
        protected bool Disposed
        {
            get
            {
                return (disposed);
            }
        }
    
        public override void Transform(Engine engine, Package package)
        {
            if( Disposed )
            {
                 throw new ObjectDisposedException();
            }
    
            Initialize(engine, package);
            m_Logger.Info("Start of Page Metadata Values");
            tc.Publication pubObject= m_Engine.GetSession().GetObject(m_Publication.Id) as tc.Publication;          
            if (pubObject != null)
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(ut.RenderPageLocale(pubObject));
            }
            package.PushItem("PageMetaDataValues", package.CreateStringItem(ContentType.Xml, RenderCurrentPageXML()));
            m_Logger.Info("End of Page Metadata Values");
        }
    
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                disposed = true;
                // Clean up all managed resources
            }
    
            // Clean up all native resources
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far i have got the code below which works lovely when trying an
I am using JQuery and I have got below JQuery Code sample. JQuery Code:
I have got the following code from here to read an Excel file using
I have got an XML document and trying to get the number of nodes
I got this error while trying to compile the below code. I would like
I have got below code in VBScript: <% Option Explicit #importXSLT tcm:228-190529-2048 As expandXSLT
I have got a list of elements that im trying to delete using the
I am using JQuery and I have below code. $(#departure_city).change(function() { $.ajax( { type:'post',
I have got some code to load an assembly and get all types, which
I'm trying to implement a horizontal multilevel dropdown navigation menu. Immediately below (vertically) the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.