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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:20:01+00:00 2026-05-13T06:20:01+00:00

I want to do do something like this : Type t=typeof(int?); or Type t=typeof(MemoryStream);

  • 0

I want to do do something like this :

Type t=typeof(int?);

or

Type t=typeof(MemoryStream);

However the parameter is string (“int?”,”MemoryStream”,etc) and it is not in assembly qualified type name so Type.GetType(string) won’t work.

The reason I need to get type is because I’m doing simple code generator application and it need to handle value & reference type different way, and also if type is Enumerable it will iterate and do specific operation.

Do you have any clue about this?

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

    Well, you could create a compiler-on-the-fly, like so:

    string getTypeHack = @"using System; public static class TypeHacker {{ public static Type GetThisType() {{ return typeof({0}); }} }}";
    
    CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
    CompilerParameters parameters = new CompilerParameters();
    parameters.GenerateInMemory = true;
    parameters.GenerateExecutable = false;
    CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, string.Format(getTypeHack, "int"));
    
    Type hacker = results.CompiledAssembly.GetType("TypeHacker");
    MethodInfo hack = hacker.GetMethod("GetThisType");
    Type actualType = (Type)hack.Invoke(null, null);
    

    … but this is probably a really bad idea. You need a new in-memory assembly for each type you are testing. Some problems off the top of my head:

    • You’re going to have memory-leakage-city with the code above; you would need to mitigate that.
    • It’s going to be slow.
    • It’s ugly.
    • You still may have assembly resolution issues, depending on which types you are allowing.

    (I might actually downvote myself for suggesting this…) :^)

    Is there any way to refactor the application to pass a Type? It’s going to make your life so much easier.

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

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer for(int i=0; i < [listOfItems count]; ++i) { Restaurant* r… May 16, 2026 at 2:28 pm
  • Editorial Team
    Editorial Team added an answer I am trying to access a link A passing the… May 16, 2026 at 2:28 pm
  • Editorial Team
    Editorial Team added an answer look on this : http://flowplayer.org/tools/demos/combine/portfolio/index.html# May 16, 2026 at 2:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have created a type like this: TypeBuilder tb = moduleBuilder.DefineType(myname, TypeAttributes.Class | TypeAttributes.Public,
Say you have some boiler plate using statements. Say something like this: #if !NUNIT
In C# I can write something like this: enum MyEnum : byte { Value1,
I would like to see if an object is a builtin data type in
Suppose I have a function which looks like this: template <class In, class In2>
I want to draw an image in PHP, which looks like the circle in
I've asked this question before but I don't think I explained myself clearly so
In Microsoft IL, to call a method on a value type you need an
To create a delegate from a method you can use the compile type-safe syntax:
I've got a generic method TResult Foo<TSource, TResult>(IEnumerable<TSource> source) and if TResult is declared

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.