Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Getting .NET types programaticly?

Getting .NET types programaticly?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikker_123
    wrote on last edited by
    #1

    Is it possible to get .NET types using some C# code? For example: private void InitializeTypes() { cmbBlah.Items.Clear(); foreach (NetType nt in GetNetTypes()) cmbBlah.Items.Add(nt.ToString()); } ? tnx in advance

    M 1 Reply Last reply
    0
    • M mikker_123

      Is it possible to get .NET types using some C# code? For example: private void InitializeTypes() { cmbBlah.Items.Clear(); foreach (NetType nt in GetNetTypes()) cmbBlah.Items.Add(nt.ToString()); } ? tnx in advance

      M Offline
      M Offline
      Marc 0
      wrote on last edited by
      #2

      The NetType you're talking about is actually System.Type[^] . You can get it using Object.GetType[^], Assembly.GetTypes[^] etc. For example, if you want to fill a combobox with all public types in your assembly, you can do:

      using System.Reflection;

      private void InitializeTypes(){
      cmbBlah.Items.Clear();

      // Get current assembly
      Assembly currentAss = Assembly.GetCurrentAssembly();
      // Get all public types from the assembly
      Type[] publicTypes = currentAss.GetExportedTypes();

      foreach (Type type in publicTypes){
      cmbBlah.Items.Add(type.ToString());
      }
      }

      Welcome to the wonderful world of reflection! :) Merry Christmas! :jig:


      "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups