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. Possible to print definition of Func<>

Possible to print definition of Func<>

Scheduled Pinned Locked Moved C#
question
3 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.
  • E Offline
    E Offline
    ezazazel
    wrote on last edited by
    #1

    Hi fellows, a question from my side again! Would really need your expertise! Is therer a way (maybe with Reflection) to get the definition of a Function? Description: I have a self defined Function (yeah I know dynamic, but here it's really neccessary, would take too long to explain):

    dynamic func = new Func((int i)=>{return 2*i;});

    Chance to get to display the part {return 2*i;} programatically? (something like

    MessageBox.Show("Function Code: {0}", functionCode);

    (int i)=>{return 2*i;} would be fine as well, just if it makes any difference :-D Thank's in advance!

    S 1 Reply Last reply
    0
    • E ezazazel

      Hi fellows, a question from my side again! Would really need your expertise! Is therer a way (maybe with Reflection) to get the definition of a Function? Description: I have a self defined Function (yeah I know dynamic, but here it's really neccessary, would take too long to explain):

      dynamic func = new Func((int i)=>{return 2*i;});

      Chance to get to display the part {return 2*i;} programatically? (something like

      MessageBox.Show("Function Code: {0}", functionCode);

      (int i)=>{return 2*i;} would be fine as well, just if it makes any difference :-D Thank's in advance!

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      Have a read of this it should give you some starters http://stackoverflow.com/questions/4986563/how-to-read-a-method-body-with-reflection[^]

      Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

      E 1 Reply Last reply
      0
      • S Simon_Whale

        Have a read of this it should give you some starters http://stackoverflow.com/questions/4986563/how-to-read-a-method-body-with-reflection[^]

        Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

        E Offline
        E Offline
        ezazazel
        wrote on last edited by
        #3

        Thank you for the link, although it seems what I need to achieve cannot be done - at least not with C#. Looks like I have to save the function definition in an attribute. D'oh

        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