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

  • Home
  • SEARCH
  • 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 7060249
In Process

The Archive Base Latest Questions

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

I have a method void InitAndLoadTables(DbConnection cnctn, Dictionary<string, DbTableLoadParameters> tableNamesAndParameters) where dictionary can have

  • 0

I have a method

void InitAndLoadTables(DbConnection cnctn, Dictionary<string, DbTableLoadParameters> tableNamesAndParameters)

where dictionary can have any amount of tables. Every table corresponds a class.

When I iterate through all the tables I would like to call generic method

public void Init<T>(string tableName)

for all the tables. I tried to include type of the class to be property of DbTableLoadParameters as

Type ObjectType { get; set; }

and use that when calling Init. This does not work. So is it even possible to do? If the amount of tables would be fixed I could maybe make InitAndLoadTables generic like

InitAndLoadTables<T, K, V>

but it isn’t. So is only possibility to call Init elsewhere like

Init<Orders>("Orders");

Thanks & BR -Matti

  • 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-28T04:19:48+00:00Added an answer on May 28, 2026 at 4:19 am

    There is no way to pass an arbitrary number of type arguments to a generic method, because a generic method always has a fixed number of type arguments.

    However, you don’t even seem to need that. There is a way to call a generic method with a runtime-known type, but this involves reflection, which sounds like it’s what you’re really after:

    class Program
    {
        static void Main(string[] args)
        {
            var myobj = new MyClass();
    
            // Call MyClass.Init<Orders>
            CallMyClassInit(typeof(Orders), "tableOrders");
    
            // Call Init<string>
            CallMyClassInit(typeof(string), "tableString");
        }
    
        static void CallMyClassInit(MyClass obj, Type type, string tableName)
        {
            typeof(MyClass)
                .GetMethod("Init")
                .MakeGenericMethod(type)
                .Invoke(obj, new object[] { tableName });
        }
    }
    
    class Orders { }
    
    class MyClass
    {
        public void Init<T>(string tableName)
        {
            Console.WriteLine("I was called with type " + typeof(T) + " for table " + tableName);
        }
    }
    

    Output:

    I was called with type ConsoleApplication1.Orders for table tableOrders
    I was called with type System.String for table tableString
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have method: void foo(const std::string& s); Can I create boost::function: boost::function<void(const std::string&)>
I have the following method: public void PutFile(string ID, Stream content) { try {
I have the following method public static void SerializeToXMLFile(Object obj,Type type, string fileName) {
If I have a method such as: public void MyMethod(int arg1, string arg2) How
I have this method to transfer files using a FTP Server: private void TransferNeededFiles(IEnumerable<string>
If I have a method - (void) myMethod:(NSString *)string { [Object anothermethodWithString:string]; } and
I'm trying to have method void run( string method ) which would run method
I have a following method private void SetProcessDocumentStatus(string status) { var setStatusWith = new
I have this method: - (void)postDictionary:(NSDictionary *)dictionary toURL:(NSURL *)url forDelegate:(id)delegate withIdentifier:(NSString *)identifier; I want
I have a method: void Foo::Bar(const std::string &str) { printf(%d, str.length()); } and it

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.