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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:03:24+00:00 2026-06-16T05:03:24+00:00

If I have a type, like: Type type = myObject.GetType (); How do I

  • 0

If I have a type, like:

Type type = myObject.GetType ();

How do I make a generic delegate that uses objects of that that type as a parameter? I would expect code something like:

myDelegate = Action<type> (type parameter);

The above code obviously won’t and doesn’t work as is, but how can I make it work? Can I even make it work?

Ultimately, I have a dictionary of Dictionary < Type, List < Action < > >, which holds a type and a list of delegates that should take an object of that type as parameter.

And should be executed something like this:

myDict[myType][i] (objectOfMyType);

Any suggestions would be greatly appreciated.

Thanks!

  • 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-16T05:03:25+00:00Added an answer on June 16, 2026 at 5:03 am

    As you might expect, you can’t use instantiations of the Action<> type directly in the dictionary. You’ll have to type it to System.Delegate, and use DynamicInvoke:

    Dictionary<Type, List<Delegate>> dict;
    
    dict[myType][i].DynamicInvoke(objectOfMyType);
    

    and to create the delegates in the first place, use reflection:

    Type delegateType = typeof(Action<>).MakeGenericType(myType);
    
    MethodInfo delegatedMethod = typeof(ContainingType).GetMethod("MethodToInvoke");
    
    Delegate myDelegate = Delegate.CreateDelegate(delegateType, delegatedMethod);
    dict.Add(myType, new List<Delegate> {myDelegate});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have generic type that looks like: public class GenericClass<T, U> where T :
I have an object that has a KeyValuePair type property. I would like to
I have an object in Javascript that looks like this function MyObject(){ this.name=; this.id=0;
I have several templated objects that all implement the same interface: I.E. MyObject<datatype1> obj1;
I have a column model like that: ... {name:'password',index:'password', width:100}, {name:'type.name',index:'type.name', width:100}, ... My
I have an object that looks like this: public class MyObject { public int
I have a custom type MyClass and a factory class Factory that creates objects
I would like to have a c.g.c.c.Multimap that is sorted based on keys only.
I have an object that looks like this: var MyObject = { prop1 =
I have a QFlag that I have created. I would like to use this

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.