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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:21:26+00:00 2026-06-09T11:21:26+00:00

I have something like this public void FunctionName<T>(){ } and to call this you

  • 0

I have something like this

public void FunctionName<T>(){

}

and to call this you need something like this

sub main(){
    FunctionName<Integer>();
}

my question is can i pass the Integer as “Integer”?

sub main(){
    FunctionName<"Integer">();
}

or is there any other way to that

Ok here is my actual code

private static T Convert<T>(DataRow row) where T : new()
{
    T model = new T();
    Type modelType = model.GetType();
    FieldInfo[] fields = null;
    FieldInfo field = default(FieldInfo);
    Type fieldType = null;
    string fieldName = null;

    fields = modelType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);

    foreach ( field in fields) {
        fieldType = field.FieldType;
        fieldName = field.Name.Replace("_", string.Empty);
        Interaction.CallByName(model, fieldName, Microsoft.VisualBasic.CallType.Set, GetValue(row, fieldName, fieldType.Name));
    }

    return model;
}


static void main(){
    Student s;

    s = Convert<Student>(DatabaseRow);
}

The problem here is I just can only get the Student as
string (“Student”) from somewhere that will use this code
Any other solution to get this right?

  • 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-09T11:21:29+00:00Added an answer on June 9, 2026 at 11:21 am

    Without seeing more of your code, it’s hard to say for sure whether you have a legitimate use-case for invoking a method like this. But regardless, assuming FunctionName is contained in class Foo, then you can invoke the method using reflection:

    var foo = new Foo();
    var typeName = "System.Int32";
    var method = typeof(Foo).GetMethod("FunctionName");
    var genericMethod = method.MakeGenericMethod(Type.GetType(typeName));
    genericMethod.Invoke(foo, new Type[0]);
    

    Note that we can’t use Integer since that’s not the real type name. (it’s either int or Int32 in C# but only Int32 is legal for GetType since int is baked into the compiler) Also, all the usual caveats about getting a type via Type.GetType apply here (there are many situations where it won’t find your custom type).

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

Sidebar

Related Questions

For example can i have something like this: public static void SAMENAME (sameparameter n)
Basically I have something like this: public void Form1_btnStart_click() { Void1() NextLine } Public
I basically have something like this: class CGlToolBase { public: CGlToolBase(void) { } virtual
Suppose I have something like this: public abstract class AbstractDataObject { public abstract void
So if i have something like this: public class TestClass { public static void
Lets say I have something like this: private CancellationTokenSource myToken; public void MyMyMethod() {
I have something like this: public void Delete(T entity) { Context.DeleteObject(entity); Context.SaveChanges(); } I
I have a method that contains an asynchronous call like this: public void MyMethod()
Suppose I have something like this: class A { public B mem; public int
I have something like this in my Spring Application: public class Book{ public Book(){

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.