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 8454609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:04:15+00:00 2026-06-10T12:04:15+00:00

I have an application which reads a specific file format. Additionally, the application supports

  • 0

I have an application which reads a specific file format. Additionally, the application supports “plugins” which read alternate file formats, and convert them into the standardized format the tool natively supports.

I would like to define an interface something like this:

/// <summary>
/// Interface for file transformer. Implementers of this interface provide a means to
/// convert a given file into Foo Format.
/// </summary>
public interface IFileTransformerPlugin
{
    /// <summary>Gets the name of the transformer to display to the user.</summary>
    /// <value>The name of the transformer displayed to the user.</value>
    string DisplayName
    {
        get;
    }

    /// <summary>Determines if this transformer can handle the given format.</summary>
    /// <remarks>
    /// This method should return very quickly; reading only a small portion of the
    /// input stream. This method is intended to be a rough cut check -- returning true
    /// does not necessarily mean that the file will parse successfully on full load.
    /// </remarks>
    /// <param name="fileContents">The file contents.</param>
    /// <returns>
    /// true if this transformer can handle the supplied format, false otherwise.
    /// </returns>
    bool CanHandleLogFormat(Stream fileContents);

    /// <summary>Transforms a file into Foo Format.</summary>
    /// <param name="inputFile">The input log stream.</param>
    /// <param name="outputFile">The output log stream (where the output should be
    /// written).</param>
    /// <returns>A transformation result which includes error information.</returns>
    LogTransformationResult Transform(Stream inputFile, Stream outputFile);
}

The problem comes from the transform method taking streams. Conceptually, I would like the plugin host, rather than the plugin, to “own” these streams, and be responsible for calling IDispose or whatever on these streams. For instance, under testing scenarios it would be nice for the caller to be able to pass a MemoryStream as the output, and then verify that the output is valid.

However, as a plugin author, it is desirable to be able to use the upper level formatting constructs in the framework; namely TextReader/TextWriter; XmlTextReader/XmlTextWriter; etc. But these classes take ownership of the underlying stream and call Dispose on the underlying stream, regardless of what the code providing the stream does. (At least, assuming those classes themselves are disposed correctly)

How might I rework this interface to get around this problem? Is it even a solvable problem?

  • 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-06-10T12:04:16+00:00Added an answer on June 10, 2026 at 12:04 pm

    This invokes the classic software engineering line: “every problem can be solved with an extra level of indirection”. Just wrap the stream and provide one-liner methods that delegate to the base stream. Except for the Dispose method, do nothing so that whatever the client code does, you keep control of the stream. Like:

    public class OwnedStream : Stream {
        private Stream stream;
        public OwnedStream(Stream stream) { this.stream = stream; }
        protected override void Dispose(bool disposing) {
            // Do nothing
        }
        public override bool CanRead { get { return stream.CanRead; } }
    
        // etcetera, just delegate to "stream"
    }
    

    Do note the other side of that medal: you are handing a reference to other code. It can store it, you’ll have no idea when they are done with it.

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

Sidebar

Related Questions

I have a silverlight application which reads data from a db and displays them
I have a java application which needs to read and write files to HDFS.
We are developing an application which is read heavy and could possibly have millions
I have read from some article that say's Apple doesn't approve the application which
I have application which uses Sherlock ActionBar package. The application uses platform-specific behavior for
I have a service application that on startup reads an XML file and starts
I do have a program which logs some specific events in a text file
I have application which needs to use a dll (also written by me) which
I have an application which uses the microsoft kinect device. The thing is that
I have an application which logs in into a webservice. I start a new

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.