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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:10:19+00:00 2026-05-28T16:10:19+00:00

I have a class that holds a dictionary of parameters: public class Parameter :

  • 0

I have a class that holds a dictionary of parameters:

public class Parameter : IExecutionParameter, IDesignerParameter
{
}

public interface IExecutionSettings
{
  IDictionary<string, IExecutionParameter> Parameters { get; }
}

public interface IDesignerSettings
{
  IDictionary<string, IDesignerParameter> Parameters { get; }
}

public class Settings : IExecutionSettings, IDesignerSettings
{
  private Dictionary<string, Parameter> _parameters;

  // TODO: Implement IExecutionSettings.Parameters
  // TODO: Implement IDesignerSettings.Parameters
}

I want to create explicit implementations of these interfaces (this I know how to do), but I can’t figure out how to properly cast the dictionary.

Any help will be appreciated.

  • 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-28T16:10:20+00:00Added an answer on May 28, 2026 at 4:10 pm

    You can’t, because it wouldn’t be safe. Suppose you could cast Dictionary<string, MemoryStream> to IDictionary<string, IDisposable> – you’d then be able to put any IDisposable value in the dictionary via the latter reference, even though the actual dictionary can only hold MemoryStream-compatible references.

    You could potentially create a readonly dictionary wrapper which delegates to an underlying dictionary for all reads, and fails on all writes. You could then wrap your Dictionary<string, Parameter> in two of these “view” dictionaries. It would be a bit of a pain, but doable. Whether or not that’s the most appropriate approach in your case is a different matter.

    Perhaps instead you should have:

    public interface IExecutionSettings
    {
        IExecutionParameter this[string key] { get; }
    }
    
    public interface IDesignerSettings
    {
        IDesignerParameter this[string key] { get; }
    }
    

    You could easily implement both of those (explicitly) within Settings.

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

Sidebar

Related Questions

I have an abstract base class that holds a Dictionary. I'd like inherited classes
I have a specialized list that holds items of type IThing : public class
I have a static class that holds a dictionary of objects. I have multiple
I have static class that holds some info public static class SampleDataCache { private
I have a Candidades class that holds Candidate objects, as follow: import java.util.*; public
I have a class that holds several vectors of objects: struct ComponentA { public:
I have a class Team that holds a generic list: [DataContract(Name = TeamDTO, IsReference
I have a private class variable that holds a collection of order items: Private
I have a class includes.vb that holds some variables (sharing them with other pages)
I have a class in C++ that I can't modify. However, that class holds

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.