473,320 Members | 2,097 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,320 software developers and data experts.

Type question

Hi,

is there a way to get the declaration name/information of the type:

namespace MySpace {
internal class MyClass {
internal void Foo() {
int i = 0;
PrintInfo( i );
}
}
}

// . . .
static void PrintInfo( object o ) {
Type t = o.GetType();
// ? ? ?
}

I want that PrintInfo would print something like "Declaration:
MySpace.MyClass.Foo int i"!

I can get the int-part (hehe), but the rest...

thx

Kimmo Laine
Nov 16 '05 #1
3 1024
Kimmo,

Generally speaking, you should be able to get up to "Foo" (namespace,
class, method). The Reflection APIs will give you this.

However, if you want to get "i", that's a little harder. You can
probably read the IL and determine that there is a variable of type int
initialized to 0, but it being named "i", that's only possible if you have
debug information in the assembly. If that is the case, then you can read
the source (however, you would have to do some parsing and matching), and
then get the variable name. As far as I know, there is nothing in the
framework that will aid you tremendously in this respect.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:Oa*************@TK2MSFTNGP09.phx.gbl...
Hi,

is there a way to get the declaration name/information of the type:

namespace MySpace {
internal class MyClass {
internal void Foo() {
int i = 0;
PrintInfo( i );
}
}
}

// . . .
static void PrintInfo( object o ) {
Type t = o.GetType();
// ? ? ?
}

I want that PrintInfo would print something like "Declaration:
MySpace.MyClass.Foo int i"!

I can get the int-part (hehe), but the rest...

thx

Kimmo Laine

Nov 16 '05 #2
Kimmo Laine <reply.to@newsgroup> wrote:
is there a way to get the declaration name/information of the type:

namespace MySpace {
internal class MyClass {
internal void Foo() {
int i = 0;
PrintInfo( i );
}
}
}

// . . .
static void PrintInfo( object o ) {
Type t = o.GetType();
// ? ? ?
}

I want that PrintInfo would print something like "Declaration:
MySpace.MyClass.Foo int i"!

I can get the int-part (hehe), but the rest...


All that has been passed to PrintInfo is the value, a reference to a
boxed int, 0. There is nothing which links it to MySpace.MyClass.Foo.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Hi Kimmo,

No it is not possible.
Firstly because *i* is local variable and it is not part of any class
declaration. Secondly....If it was memeber of a type you could've probably
passed MemberInfo to the *PrintInfo* method, but passing instance of a type
doesn't give you any informaton beside you can get info regarding the type
of the object. This is not what you want as far as I understand.

--

Stoitcho Goutsev (100) [C# MVP]
"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:Oa*************@TK2MSFTNGP09.phx.gbl...
Hi,

is there a way to get the declaration name/information of the type:

namespace MySpace {
internal class MyClass {
internal void Foo() {
int i = 0;
PrintInfo( i );
}
}
}

// . . .
static void PrintInfo( object o ) {
Type t = o.GetType();
// ? ? ?
}

I want that PrintInfo would print something like "Declaration:
MySpace.MyClass.Foo int i"!

I can get the int-part (hehe), but the rest...

thx

Kimmo Laine

Nov 16 '05 #4

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

Similar topics

9
by: Andrew | last post by:
It seems that in C#, given an instance "a" of some value type "A", one can pass a by reference to functions with signatures of either "void f(object obj)" or "void g(ref A obj)". But passing a into...
4
by: Richard Lee | last post by:
Hi, I have a question when I do a data type cast. the common way when we do a cast, is we know the type we want to cast to, i.e. we want to cast object to string, object xyz = "question";...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
10
by: Qwert | last post by:
Hello, is it correct that if a type (System.Type) is a value (.IsValueType=True) and not primitive (.IsPrimitive=False), that type is a structure? Thanks.
7
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
2
by: Arndt Jonasson | last post by:
This is a modelling style question, I think. I am working with a somewhat XML Schema-like formalism which defines the structure of an instance document, supplying a number of built-in types (a...
3
by: Lord0 | last post by:
I am trying to implement variable content containers using an abstract type and type substitution. My schema is as follows: <?xml version="1.0" encoding="UTF-8"?> <schema...
25
by: SRR | last post by:
Consider the following code: #include <stdio.h> #include <string.h> struct test{ char a; } funTest( void ); int main( void ) {
2
by: Barry | last post by:
The problem brought by one earlier post from comp.lang.c++ http://groups.google.com/group/comp.lang.c++/browse_thread/thread/bf636c48b84957b/ I take part of the question and reproduce the code to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.