By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,783 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,783 IT Pros & Developers. It's quick & easy.

How can I get the namespace in a function

P: n/a
ad
Hi,
I have a function in a Class.
How can I get the name of the calss's namespace ?
May 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"ad" <fl****@wfes.tcc.edu.tw> wrote:
I have a function in a Class.
In what way do you have a function? In a delegate? As a MethodInfo?
How can I get the name of the calss's namespace ?


The full name of the class includes the namespace as part of its name.
If you have a MethodInfo, the namespace is:

---8<---
MethodInfo m;
// ...
Console.WriteLine(m.DeclaringType.FullName);
--->8---

If you have a delegate, you can get the method for each delegate with:

---8<---
Delegate d;
// ...
foreach (MethodInfo m in d.GetInvocationList())
Console.WriteLine(m.DeclaringType.FullName);
--->8---

-- Barry
May 16 '06 #2

P: n/a
Just little a little suggestion...

One one has the declaring type (Type object) one can simply read
Type.Namespace proeprty. Using FullName requires some parsing of the string
as the type might be nested in other types.
--

Stoitcho Goutsev (100)

"Barry Kelly" <ba***********@gmail.com> wrote in message
news:df********************************@4ax.com...
"ad" <fl****@wfes.tcc.edu.tw> wrote:
I have a function in a Class.


In what way do you have a function? In a delegate? As a MethodInfo?
How can I get the name of the calss's namespace ?


The full name of the class includes the namespace as part of its name.
If you have a MethodInfo, the namespace is:

---8<---
MethodInfo m;
// ...
Console.WriteLine(m.DeclaringType.FullName);
--->8---

If you have a delegate, you can get the method for each delegate with:

---8<---
Delegate d;
// ...
foreach (MethodInfo m in d.GetInvocationList())
Console.WriteLine(m.DeclaringType.FullName);
--->8---

-- Barry

May 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.