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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:25:50+00:00 2026-05-26T21:25:50+00:00

I have a bunch of classes that all contain a Shared ReadOnly Dictionary. If

  • 0

I have a bunch of classes that all contain a Shared ReadOnly Dictionary. If I want to access that Dictionary when the class is a generic type (such as when I have a wrapper function that takes T as an interface that all of these classes implement), what’s the way to do it?

Basic research suggests I want to do something like GetType(T).GetMember("Dict"), but that will return a MemberInfo type, and that cannot be cast to a Dictionary of my defined type(s). For calling functions this way, one can use a delegate + CreateDelegate + GetMethod. But there doesn’t seem to be an equivalent Create*for GetMember stuff. Or am I missing something?

If I plug the GetMember call into the immediate window, and then use a subscript as if it is an array, then the debug output says I am getting a Dictionary back. But if I use that same approach in the actual function that I am trying to write, then I get an error about System.Reflection.MemberInfo cannot be converted to Dictionary(X, Y)

  • 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-26T21:25:50+00:00Added an answer on May 26, 2026 at 9:25 pm

    You’re nearly there.

    GetMember returns an array of all the members with the name you pass (you can pass a string containing a wildcard * and get back multiple members). So in this case, you must index into the return value to get the actual MemberInfo you want.

    Then in order to do anything with it, you’ll need to cast it to the actual -Info type that it is, in this case a FieldInfo.

    Once you’ve got a FieldInfo, you can call GetValue on it to get the actual value of the field. You’ll need to pass Nothing to GetValue, since the field is shared, so the ‘instance’ you want to get this field’s value for isn’t an instance at all.

    Finally you’ll need to cast the return value of GetValue to your actual dictionary type, since it’s typed as Object.

    Then you can look in your dictionary.

    This might seem long winded but only because I have spelled it out – if you are happy to go without error checking (which you should be, once it works), this will be a couple of lines at most.

    The reason the Immediate Window ‘just works’ is because the debugger is doing all this for you behind the scenes. It’s very helpful like that.

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

Sidebar

Related Questions

I have a bunch of classes in a C# class library that I bought
I want to control the creation of a bunch of classes that all share
Maybe I'm going about this all wrong. I have a bunch of classes that
I have a bunch of classes I want to rename. Some of them have
I have a bunch of generic interfaces and classes public interface IElement { //
imagine I have a bunch of C++ related classes (all extending the same base
We have a bunch of classes that listen for events from the server and
I have a ListView-derived class which creates a bunch of user controls that are
Here is my problem. I have a bunch of Configuration classes that get serialized
I have a bunch of JAXB annotated classes that have a field in common,

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.