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

  • Home
  • SEARCH
  • 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 79731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:11:30+00:00 2026-05-10T21:11:30+00:00

The current guidlelines for explicit member implementation recommend: Using explicit members to approximate private

  • 0

The current guidlelines for explicit member implementation recommend:

  • Using explicit members to approximate private interface implementations. If you need to implement an interface for only infrastructure reasons and you never expect developers to directly call methods on that interface from this type then implement the members explicitly to ‘hide’ them from public view.
  • Expose an alternative way to access any explicitly implemented members that subclasses are allowed to override.

A good example of this is when you want to implement the IXmlSerializable interface. The ReadXml and WriteXml methods are expected to be called by the XmlSerializer and are not typically called directly by developers.

When providing an alternative way to access explicitly members you wish to allow to be overridden, it seems to make sense to call the explicitly implemented member so as to avoid code duplication. Consider the following:

using System; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization;  namespace Demo {     /// <summary>     /// Demonstrates explicit implementation of the IXmlSerializable interface.     /// </summary>     [Serializable(), XmlRoot(ElementName = 'foo')]     public class Foo : IXmlSerializable     {         //============================================================         //  IXmlSerializable Implementation         //============================================================         #region GetSchema()         /// <summary>         /// Returns an <see cref='XmlSchema'/> that describes the XML representation of the object.         /// </summary>         /// <returns>         /// An <see cref='XmlSchema'/> that describes the XML representation of the object that is          /// produced by the <see cref='IXmlSerializable.WriteXml(XmlWriter)'/> method and consumed by the <see cref='IXmlSerializable.ReadXml(XmlReader)'/> method.         /// </returns>         /// <remarks>This method is reserved and should not be used.</remarks>         XmlSchema IXmlSerializable.GetSchema()         {             return null;         }         #endregion          #region ReadXml(XmlReader reader)         /// <summary>         /// Generates an object from its XML representation.         /// </summary>         /// <param name='reader'>The <see cref='XmlReader'/> stream from which the object is deserialized.</param>         /// <exception cref='ArgumentNullException'>The <paramref name='reader'/> is a <b>null</b> reference (Nothing in Visual Basic).</exception>         void IXmlSerializable.ReadXml(XmlReader reader)         {             // Class state values read from supplied XmlReader         }         #endregion          #region WriteXml(XmlWriter writer)         /// <summary>         /// Converts an object into its XML representation.         /// </summary>         /// <param name='writer'>The <see cref='XmlWriter'/> stream to which the object is serialized.</param>         /// <exception cref='ArgumentNullException'>The <paramref name='writer'/> is a <b>null</b> reference (Nothing in Visual Basic).</exception>         void IXmlSerializable.WriteXml(XmlWriter writer)         {             // Current class state values written using supplied XmlWriter         }         #endregion          //============================================================         //  Public Methods         //============================================================         #region WriteTo(XmlWriter writer)         /// <summary>         /// Saves the current <see cref='Foo'/> to the specified <see cref='XmlWriter'/>.         /// </summary>         /// <param name='writer'>The <see cref='XmlWriter'/> stream to which the <see cref='Foo'/> is serialized.</param>         /// <exception cref='ArgumentNullException'>The <paramref name='writer'/> is a <b>null</b> reference (Nothing in Visual Basic).</exception>         public void WriteTo(XmlWriter writer)         {             writer.WriteStartElement('foo');              ((IXmlSerializable)this).WriteXml(writer);              writer.WriteEndElement();         }         #endregion     } } 

My question is in regards to how expensive the boxing of the WriteXml method is in this implementation. Is ((IXmlSerializable)this).WriteXml(writer) going to significantly hinder performance?

  • 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. 2026-05-10T21:11:31+00:00Added an answer on May 10, 2026 at 9:11 pm

    There’s no boxing taking place in your example… it’s just a cast, and it’s resolvable at compile time, so it should not have any impact on performance at all.

    Edit: Looking at it with ILDASM, the interface cast will give you a virtual method call versus a regular method call, but this is negligible (there is still no boxing involved).

    Edit 2: If you use a struct instead of a class, THEN you will get a box going through the interface, with much more of a performance penalty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Why not use array_map()? array_map(mysql_real_escape_string, $_POST); But in reality you… May 11, 2026 at 3:28 pm
  • added an answer The CPU sets those flags after carrying out arithmetic operations.… May 11, 2026 at 3:28 pm
  • added an answer For this to work, you need 1) a way to… May 11, 2026 at 3:28 pm

Related Questions

Introduction I've always been searching for a way to make Visual Studio draw a
I just wonder what the best approach is to have multiple users work on
The Framework Design Guidelines (2nd Ed., page 327) say: CONSIDER providing method Close() ,
When implementing IDisposable correctly, most implementations, including the framework guidelines, suggest including a private

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.