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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:31:50+00:00 2026-05-13T19:31:50+00:00

I have this Class which is accepting a Dictionary<string,object> which is been invoked from

  • 0

I have this Class which is accepting a Dictionary<string,object> which is been invoked from different places in the code. Dictionary concept is making things untyped and difficult to figure out what to pass the class to function otherwise it throws run-time exception. As this Dictionary<string,object> is a contract definition so i had to write an extension method to convert my type to a dictionary when invoking my class . But now how can i close this Class that it only accepts a specific Type

So for eg.

public class CreateReport : IRep
{

public void SetParam(Dictionary<string,object> parm)
{
 // Here the dictionary param are been set. 
}

 public object RunRep()
{

}
}

ClassInvoker.Invoke(CreateReport , Dictionary<string,object>{"MyParam" , "World"});

So this is how things are now.

I have changed it by creating a Property class as

public class CreateReportProp
{
  public string MyParam { get;set;}
}

and having a extension method as ConvertObjToDict

so Now we have to do something like

ClassInvoker.Invoke(CreateReport , new CreateReportProp { MyParam = "World"}.ConvertObjToDict());

But i would like to go further and close the Class so that CreateReportClass you can only Pass CreateReportParam otherwise compiler throws an exception.

Please give me some ideas as how can i acheive this.

  • 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-13T19:31:50+00:00Added an answer on May 13, 2026 at 7:31 pm

    I presume you are using the CreateReport class for many specific reports? If this is the case, the you have a chance to enact a compile-time check. If the CreateReport class dynamically invokes the report, i.e. by name, and each report has different parameter requirements, then there is no compile-time check possible.

    In the first case, you would change the signature for the CreateReport class as follows:

    public class CreateReport<T> : IRep, where T : CreateReportProp
    

    In the SetParam method, you would have

    public void SetParam(T param)
    

    For each specific report you can create a different property class as long as it inherits from CreateReportProp. Then when you instance the report class you will specify that one.

    CreateReport<MySpecificParam> myReport = new CreateReport<MySpecificParam>();
    myReport.SetParam( new MySpecificParam() {...});
    

    If you wish to do less changes within the CreateReport class you can have your CreateReportProp implement an IEnumerable or IDictionary interface so that iterating the parameters is more generic.

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

Sidebar

Ask A Question

Stats

  • Questions 373k
  • Answers 373k
  • 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
  • Editorial Team
    Editorial Team added an answer Use: html, body, form, fieldset, p, div, h1, h2, h3,… May 14, 2026 at 7:47 pm
  • Editorial Team
    Editorial Team added an answer you just need to prepend ^.*\ to your regex. May 14, 2026 at 7:47 pm
  • Editorial Team
    Editorial Team added an answer The main reasons why these two examples are so different… May 14, 2026 at 7:47 pm

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.