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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:08:17+00:00 2026-05-19T06:08:17+00:00

I have a list of types (System.Type) which need te be queried on the

  • 0

I have a list of types (System.Type) which need te be queried on the database.

For each of this types, I need to call the following extensionmethod (which is part of LinqToNhibernate):

Session.Linq<MyType>()

However I do not have MyType, but I want to use a Type instead.

What I have is:

System.Type typeOne;

But I cannot perform the following:

Session.Linq<typeOne>()

How can I use a Type as a Generic parameter?

  • 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-19T06:08:19+00:00Added an answer on May 19, 2026 at 6:08 am

    You can’t, directly. The point of generics is to provide compile-time type safety, where you know the type you’re interested in at compile-time, and can work with instances of that type. In your case, you only know the Type so you can’t get any compile-time checks that any objects you have are instances of that type.

    You’ll need to call the method via reflection – something like this:

    // Get the generic type definition
    MethodInfo method = typeof(Session).GetMethod("Linq", 
                                    BindingFlags.Public | BindingFlags.Static);
    
    // Build a method with the specific type argument you're interested in
    method = method.MakeGenericMethod(typeOne);
    // The "null" is because it's a static method
    method.Invoke(null, arguments);
    

    If you need to use this type a lot, you might find it more convenient to write your own generic method which calls whatever other generic methods it needs, and then call your method with reflection.

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

Sidebar

Related Questions

I have the following LINQ query: List<string> Types = (List<string>)Directory.GetFiles(@C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727) .Where(x => System.IO.Path.GetFileNameWithoutExtension(x).Contains(Microsoft)) .ToList<string>();
I have an html ordered list with differnent types e.g <ol type=a> <li>This is
I have system in which I need to display the list of records such
I have two different list types. I need to remove the elements from list1
I have a class CustomCollection : IList which maintains a list of CustomObject Types.
I have a list of type stored procedure which have an ID and a
I have created the following type using implicit type construction: open System type Matrix(sourceMatrix:double[,])
I have a List of objects, which are of my type QuoteHeader and I
Just need some help with this. I have written a WCF service which passes
I have create a restful service which returning a List an entity type: [AspNetCompatibilityRequirements(RequirementsMode

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.