How can I get the namespace in a function

  • Thread starter Thread starter ad
  • Start date Start date
ad said:
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
 
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.
 

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

Back
Top