Reverse-engineering C# Classes

O

O.B.

I'm trying to design a tool to reverse-engineer C# class files (not
compiled) and I am having difficulty identify which namespace a class
belongs. For example, the top of the class has "using
System.Threading" and later in the class there is a "Thread myThread =
null". There is no way to determine by looking at solely the cs file
that Thread belongs in the System.Threading namespace.

Are there other files within the .NET installation to aid in
determining a solution for this problem?
 
N

Nicholas Paldino [.NET/C# MVP]

O.B.

Well, that's not technically true, since the compiler does it just fine.
You would have to look at the C# specification for resolving types.

Are you using CodeDom for this? If so, you should be able to get the
statement and figure out the type from that pretty easily.

If you aren't using the CodeDom then I would strongly suggest reading
the C# language specification and use that to construct your type resolution
algorithm.
 
A

Anthony Jones

O.B. said:
I'm trying to design a tool to reverse-engineer C# class files (not
compiled) and I am having difficulty identify which namespace a class
belongs. For example, the top of the class has "using
System.Threading" and later in the class there is a "Thread myThread =
null". There is no way to determine by looking at solely the cs file
that Thread belongs in the System.Threading namespace.

Are there other files within the .NET installation to aid in
determining a solution for this problem?

If you already have a CS file what type of file is the output of such a
reverse engineering?

Functional Spec?
 
G

Gregory A. Beamer

O.B. said:
I'm trying to design a tool to reverse-engineer C# class files (not
compiled)

I do not call this reverse engineering unless there is an artifact that
could have been originally engineered to create the code. What are you
trying to "reverse engineer" the file to? IE, what is the output.

--
Gregory A. Beamer
MVP: MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think Outside the Box! |
********************************************
 
O

O.B.

I do not call this reverse engineering unless there is an artifact that
could have been originally engineered to create the code. What are you
trying to "reverse engineer" the file to? IE, what is the output.

UML
 
O

O.B.

Is there anything like header files or an XML file for the C# language
specification?


O.B.

    Well, that's not technically true, since the compiler does it just fine.
You would have to look at the C# specification for resolving types.

    Are you using CodeDom for this?  If so, you should be able to get the
statement and figure out the type from that pretty easily.

    If you aren't using the CodeDom then I would strongly suggest reading
the C# language specification and use that to construct your type resolution
algorithm.

--
          - Nicholas Paldino [.NET/C# MVP]
          - (e-mail address removed)


I'm trying to design a tool to reverse-engineer C# class files (not
compiled) and I am having difficulty identify which namespace a class
belongs.  For example, the top of the class has "using
System.Threading" and later in the class there is a "Thread myThread =
null".  There is no way to determine by looking at solely the cs file
that Thread belongs in the System.Threading namespace.
Are there other files within the .NET installation to aid in
determining a solution for this problem?
 
O

O.B.

I presume you're aware there are products that do this already?

John

Yes, but some don't do it very well. I'd like to write a simple
program to show them just how easy it really is.
 
N

Nicholas Paldino [.NET/C# MVP]

Google "C# language specification" and it will be the first or second
link. You can download it in Word format.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Is there anything like header files or an XML file for the C# language
specification?


O.B.

Well, that's not technically true, since the compiler does it just fine.
You would have to look at the C# specification for resolving types.

Are you using CodeDom for this? If so, you should be able to get the
statement and figure out the type from that pretty easily.

If you aren't using the CodeDom then I would strongly suggest reading
the C# language specification and use that to construct your type
resolution
algorithm.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I'm trying to design a tool to reverse-engineer C# class files (not
compiled) and I am having difficulty identify which namespace a class
belongs. For example, the top of the class has "using
System.Threading" and later in the class there is a "Thread myThread =
null". There is no way to determine by looking at solely the cs file
that Thread belongs in the System.Threading namespace.
Are there other files within the .NET installation to aid in
determining a solution for this problem?
 
N

Nicholas Paldino [.NET/C# MVP]

Agreed. You beat me to it.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peter Duniho said:
[...]
I presume you're aware there are products that do this already?

Yes, but some don't do it very well. I'd like to write a simple
program to show them just how easy it really is.

I find this statement ironic, given the original question for this
thread. :)
 
G

Gregory A. Beamer

Ditto!

ROFLMAO!

--
Gregory A. Beamer
MVP: MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think Outside the Box! |
********************************************
Nicholas Paldino said:
Agreed. You beat me to it.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peter Duniho said:
[...]
I presume you're aware there are products that do this already?

Yes, but some don't do it very well. I'd like to write a simple
program to show them just how easy it really is.

I find this statement ironic, given the original question for this
thread. :)
 
J

J.B. Moreno

Well, that's not technically true, since the compiler does it just fine.

Actually the compiler doesn't do that, it does something different --
when compiling the cs file, it brings in information from the
System.Threading namespace just like the cs file says to.

O.B. is right that there's no way to determine what namespace it
belongs to, and that is inherent in any language that can (a) import
types from external files and (b) doesn't require that the type
declaration to include the file path.

Unfortunately for O.B. that pretty much describes most languages.
 
O

O.B.

I'm looking for something like the .NET class hierarchy in an easy to
parse format (e.g. XML). Word is rather useless.


    Google "C# language specification" and it will be the first or second
link.  You can download it in Word format.

--
          - Nicholas Paldino [.NET/C# MVP]
          - (e-mail address removed)


Is there anything like header files or an XML file for the C# language
specification?

Well, that's not technically true, since the compiler does it just fine..
You would have to look at the C# specification for resolving types.
Are you using CodeDom for this? If so, you should be able to get the
statement and figure out the type from that pretty easily.
If you aren't using the CodeDom then I would strongly suggest reading
the C# language specification and use that to construct your type
resolution
algorithm.
 
N

Nicholas Paldino [.NET/C# MVP]

The heirarchy is going to be useless to you in order to figure this out.
The reason for this is that you can have two classes with the same short
name, but in different namespaces.

The C# specification is EXACTLY what you need because you basically have
to follow the same rules that a compiler does, and a compiler is written
against THAT spec.

If you don't, your tool will not work and even worse, in some cases,
will give you the wrong answer.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I'm looking for something like the .NET class hierarchy in an easy to
parse format (e.g. XML). Word is rather useless.


Google "C# language specification" and it will be the first or second
link. You can download it in Word format.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Is there anything like header files or an XML file for the C# language
specification?

Well, that's not technically true, since the compiler does it just fine.
You would have to look at the C# specification for resolving types.
Are you using CodeDom for this? If so, you should be able to get the
statement and figure out the type from that pretty easily.
If you aren't using the CodeDom then I would strongly suggest reading
the C# language specification and use that to construct your type
resolution
algorithm.
 
O

O.B.

We are talking about two different things. Yes, it is obvious that
one needs to follow the rules as specified by the specification.
ASSUME that the C# language specification rules are already in place.
Where/How would one find the a description of the namespaces in .NET?
For example, my tool needs to determine if there is a "Thread" class
exists within the System.Threading namespace.


    The heirarchy is going to be useless to you in order to figure this out.
The reason for this is that you can have two classes with the same short
name, but in different namespaces.

    The C# specification is EXACTLY what you need because you basically have
to follow the same rules that a compiler does, and a compiler is written
against THAT spec.

    If you don't, your tool will not work and even worse, in some cases,
will give you the wrong answer.

--
          - Nicholas Paldino [.NET/C# MVP]
          - (e-mail address removed)


I'm looking for something like the .NET class hierarchy in an easy to
parse format (e.g. XML).  Word is rather useless.

Google "C# language specification" and it will be the first or second
link. You can download it in Word format.
"O.B." <[email protected]> wrote in message
Is there anything like header files or an XML file for the C# language
specification?
O.B.
Well, that's not technically true, since the compiler does it just fine.
You would have to look at the C# specification for resolving types.
Are you using CodeDom for this? If so, you should be able to get the
statement and figure out the type from that pretty easily.
If you aren't using the CodeDom then I would strongly suggest reading
the C# language specification and use that to construct your type
resolution
algorithm.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I'm trying to design a tool to reverse-engineer C# class files (not
compiled) and I am having difficulty identify which namespace a class
belongs. For example, the top of the class has "using
System.Threading" and later in the class there is a "Thread myThread =
null". There is no way to determine by looking at solely the cs file
that Thread belongs in the System.Threading namespace.
Are there other files within the .NET installation to aid in
determining a solution for this problem?
 
P

Peter Morris

Yes, but some don't do it very well. I'd like to write a simple
program to show them just how easy it really is.
<<

This is my newsgroup giggle for the day :)

Maybe you have instead learned just how easy it isn't?
 
B

Brian Simmons

Yes, but some don't do it very well. I'd like to write a simple
program to show them just how easy it really is.

Show them this thread. That'll learn 'em.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top