473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Randomly choose method and extract method body

I would welcome any advice someone could offer on the follow problem.
I need to code a command line utility in c sharp. The utility will
accept a single parameter; the name of a cs file (not an assembly). I
then need to pick a method at random and display the text of that
method contained in the cs file.

Initially i wanted to use reflection but because the utility looks at
a source file instead of a dll I don't think this will work,
furthermore I don't think reflection allows the extraction of a
method's body.

Regular expressions could be an option but my regular expression
skills are lacking.

Any ideas?

TIA.
Nov 16 '05 #1
2 1920
Hi Chris,

That sound as a homework :)

You have to differenciate between a method call and a method definition,
you can do this be either check the sintaxis of the method declaration or
how the method is called, you will have to make sure that you cover all the
possibilities of either one like:
- A method definition have a type before it and a ( after it , a number of
chars and a ) then followed by a {

When you find a method definition you then start counting by { incrementing
each time you see a { and decrementing when you see a } , when the count
reach 0 you have your method body.

Please note that the above is only to give you an idea , is not the
complete thing.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Chris Green" <us************@yahoo.com> wrote in message
news:e0**************************@posting.google.c om...
I would welcome any advice someone could offer on the follow problem.
I need to code a command line utility in c sharp. The utility will
accept a single parameter; the name of a cs file (not an assembly). I
then need to pick a method at random and display the text of that
method contained in the cs file.

Initially i wanted to use reflection but because the utility looks at
a source file instead of a dll I don't think this will work,
furthermore I don't think reflection allows the extraction of a
method's body.

Regular expressions could be an option but my regular expression
skills are lacking.

Any ideas?

TIA.

Nov 16 '05 #2
I wish it was homework, however my boss wants it for a project that he
is keeping secret at the moment. Thanks for the help.
"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us> wrote in message news:<ek**************@tk2msftngp13.phx.gbl>...
Hi Chris,

That sound as a homework :)

You have to differenciate between a method call and a method definition,
you can do this be either check the sintaxis of the method declaration or
how the method is called, you will have to make sure that you cover all the
possibilities of either one like:
- A method definition have a type before it and a ( after it , a number of
chars and a ) then followed by a {

When you find a method definition you then start counting by { incrementing
each time you see a { and decrementing when you see a } , when the count
reach 0 you have your method body.

Please note that the above is only to give you an idea , is not the
complete thing.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Chris Green" <us************@yahoo.com> wrote in message
news:e0**************************@posting.google.c om...
I would welcome any advice someone could offer on the follow problem.
I need to code a command line utility in c sharp. The utility will
accept a single parameter; the name of a cs file (not an assembly). I
then need to pick a method at random and display the text of that
method contained in the cs file.

Initially i wanted to use reflection but because the utility looks at
a source file instead of a dll I don't think this will work,
furthermore I don't think reflection allows the extraction of a
method's body.

Regular expressions could be an option but my regular expression
skills are lacking.

Any ideas?

TIA.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jane Doe | last post by:
Hi I took a quick look in the archives, but didn't find an answer to this one. I'd like to display a list of HTML files in a directory, showing the author's name between brackets after the...
2
by: neutrinman | last post by:
Hi,there. How can I choose a key in dictionary randomly? Say, random.choice() in lists, or in lists: lists = position = random.range(len(lists)) word = lists
4
by: Nathan Given | last post by:
Hello All, I am trying to randomly change the background image of my home page but I can't seem to figure it out. Here is a snippet of my css .... BODY {background:transparent...
1
by: Benny Ng | last post by:
Hi,All, Export Method: ------------------------------------------------------------------------- strFileNameExport = "Results" Response.Clear() Response.Buffer = True...
5
by: Paul Tomlinson | last post by:
How can I randomly pick either the value integer 5 or integer 8?? I don't want a value between 5 and 8 but either the values 5 or 8 randomly. Any ideas on how can I do this please?? MA
9
by: Alan Isaac | last post by:
I need access to 2*n random choices for two types subject to a constraint that in the end I have drawn n of each. I first tried:: def random_types(n,typelist=): types = typelist*n...
9
by: flit | last post by:
Hello All, Using poplib in python I can extract only the headers using the .top, there is a way to extract only the message text without the headers? like remove the fields below: "...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
9
by: Generic Usenet Account | last post by:
I had a need to randomly select an element from an STL collection. It does not appear that this functionality is provided out-of-the-box with STL. Here is my crude implementation. I am using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.