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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:43:33+00:00 2026-06-03T05:43:33+00:00

I have this method: public List<T> SomeMethod<T>( params ) where T : new() So

  • 0

I have this method:

public List<T> SomeMethod<T>( params ) where T : new()

So I want to call this SomeMethod which is fine if I know the type:

SomeMethod<Class1>();

But if I only have Class1 at runtime I’m unable to call it?

So how to call SomeMethod with unknown T type? I got Type by using reflection.

I have the Type of type but SomeMethod<Type | GetType()> doesn’t work.

Update 7. May:

Here is a sample code of what I want to achieve:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace ConsoleApplication63
{
    public class DummyClass
    {
    }

    public class Class1
    {
        public string Name;
    }

    class AssemblyTypesReflection
    {
        static void Main(string[] args)
        {
            object obj = new Class1() { Name = "John" } ;

            Assembly assembly = Assembly.GetExecutingAssembly();
            var AsmClass1 = (from i in assembly.GetTypes() where i.Name == "Class1" select i).FirstOrDefault();


            var list = SomeMethod<AsmClass1>((AsmClass1)obj); //Here it fails
        }

        static List<T> SomeMethod<T>(T obj) where T : new()
        {
            return new List<T> { obj };
        }
    }
}

This is a demo taken out of a bigger context.

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

    You need to call it using reflection:

    var method = typeof(SomeClass).GetMethod("SomeMethod");
    method.MakeGenericMethod(someType).Invoke(...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method call: public DataTemplate Create(Type type, string propertyName) { string str
I have this controller method: public JsonResult List(int number) { var list = new
I have this method public static List<SummaryItinerary> ReturnBookingsByUserGuid(Guid userGuid) { var entities = new
I have the following get method: public List<PersonalMessage> getMessagesList() { List<PersonalMessage> newList = new
I have a RPC service with the following method: public List<Serializable> myMethod(TransactionCall call) {...}
I have this action method: [HttpPost] public ActionResult GetNextImage(int m_id) { ... return Json(new{...});
I have got problem with this method: public List<int> menu_wid_w_kat() { DataSet1TableAdapters.menu_widac_wszystkoTableAdapter pk =
I have this method in a Directory model: public List<Directory> subdirectories() { return find(select
While executing this method: public static List<T> ToList<T>(DataTable dataTable) { Type type = typeof(T);
I have the following BL method public static void SomeMethod (List<SomeClass> group) { IEnumerable<SomeClass>

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.