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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:21:10+00:00 2026-05-27T07:21:10+00:00

I have wired problem, I know Inference requires the use of an open generic.

  • 0

I have wired problem, I know Inference requires the use of an open generic.

Is ther a way to call AssertDictionary(o2, o1); by Reflection.
What I want is, use Type of o1 say t1 and o2 say t2 as AssertDictionary(o1, o2);

does this make sense?

 public static void Main(String[] args)
    {
        Dictionary<int, Person> actual = new Dictionary<int, Person>();
        actual.Add(10, new Person{Address="Abc", Name = "Dipak"});

        Dictionary<int, Person> expected = new Dictionary<int, Person>();
        expected.Add(10, new Person { Address = "Abc", Name = "Dipak" });

        object o1 = actual;
        object o2 = expected;
        CallAssert(o1, o2);
    }

     private static CallAssert(object exp, object act)
     {
            AssertDictionary(exp, act);// I'm doing it at runtime by reflection and actual & expected are of type System.Object
     }


 private static void AssertDictionary<TKey, TVal>(Dictionary<TKey, TVal> expected, Dictionary<TKey, TVal> actual)
    {
        if (expected != null && actual != null)
        {
            foreach (KeyValuePair<TKey, TVal> valuePair in expected)
            .....
            .....
        }
     }

Can I create dynamic method at runtime and Call AssertDictionary from there with Generic types?

  • 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-27T07:21:10+00:00Added an answer on May 27, 2026 at 7:21 am

    If you’re sure you have to use reflection, you can do it like this (assuming Program is the type containing AssertDictionary()):

    // get the method
    var openMethod = typeof(Program).GetMethod(
        "AssertDictionary", BindingFlags.NonPublic | BindingFlags.Static);
    
    // get type arguments of the dictionary
    var dictTypeArgs = o1.GetType().GetGenericArguments();
    
    // set the type parameters of the method
    var closedMethod = openMethod.MakeGenericMethod(dictTypeArgs);
    
    // invoke the method
    closedMethod.Invoke(null, new [] { o1, o2 });
    

    Another option is to use dynamic and infer the type parameters at runtime automatically:

    AssertDictionary((dynamic)o1, (dynamic)o2);
    

    I think there is no need to create any dynamic methods here.

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

Sidebar

Related Questions

we have a particle detector hard-wired to use 16-bit and 8-bit buffers. Every now
Weired problem! ASP.NET Session expires instantly. In my web.config I have this session settings:
I have the following (fairly) simple JavaScript snippet that I have wired into Greasemonkey.
I have a asp.net webform with a button. The OnClientClick event is wired to
I'm running into a paradigm problem here. I don't know whether I should store
Assuming I have this regular expression: '#artists/(.*)/#' and I want to match this string:
I'm creating a file-browser in ASP.Net but I have run into a problem which
I know there have been discussions wrt to dbunit here. I have read most
So I've spent all day finding where the problem lies. If I don't use
The problem I have is illustrated in the following code. #include <iostream> #define X

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.