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
  1. Home
  2. General Programming
  3. C#
  4. change property return type dynamically

change property return type dynamically

Scheduled Pinned Locked Moved C#
tutorialquestion
4 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.
  • U Offline
    U Offline
    unil Dhiman
    wrote on last edited by
    #1

    I have create a property of System.object return type I want to change its Type at runtime according to my need. for example I want to convert it into System.String or System.Enum. is it possible ? Thanks.

    C 1 Reply Last reply
    0
    • U unil Dhiman

      I have create a property of System.object return type I want to change its Type at runtime according to my need. for example I want to convert it into System.String or System.Enum. is it possible ? Thanks.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can write a generic method, I'm not sure if you can write one where the generic type specifies the return type, but I expect so. Or you can cast your object to whatever you like, but the real kicker is, how do you get the method to return objects of different types all the time ? Generics will do that, but how do you define the instance of the object to have the value you want, if it could be any type of object ?

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      U 1 Reply Last reply
      0
      • C Christian Graus

        You can write a generic method, I'm not sure if you can write one where the generic type specifies the return type, but I expect so. Or you can cast your object to whatever you like, but the real kicker is, how do you get the method to return objects of different types all the time ? Generics will do that, but how do you define the instance of the object to have the value you want, if it could be any type of object ?

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        U Offline
        U Offline
        unil Dhiman
        wrote on last edited by
        #3

        I want to implement dropdown list in web parts in asp.net 2.0, so that i can implement personalization. there must be Enum to use dropdown list. I have created Enum Dynamically. I already created a Propert of System.object return type. now i want to change its return type as per Enum, i created dynamically. Thats why i need some solution of it. if you have any idea, please let me know. Thanks.

        C 1 Reply Last reply
        0
        • U unil Dhiman

          I want to implement dropdown list in web parts in asp.net 2.0, so that i can implement personalization. there must be Enum to use dropdown list. I have created Enum Dynamically. I already created a Propert of System.object return type. now i want to change its return type as per Enum, i created dynamically. Thats why i need some solution of it. if you have any idea, please let me know. Thanks.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I already told you the only solution that might possibly work.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          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