1

I want get all namespace in main project by method assembly.(Not all aseembly)

I read below question but not useful.

Getting all types in a namespace via reflection

for example

class in Assembly:

namespace test
{
    public class Class1
    {
        public string[] AllNameSpace()
        {
            return Assembly.GetExecutingAssembly().GetTypes().Select(x => x.Namespace).ToArray();
        }
    }
}

code in main project:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var util=new Class1();
            Console.WriteLine(string.Join(",",util.AllNameSpace()));//return test
            Console.ReadKey();
        }
    }
}

return "test" But I want contain ConsoleApplication1 namespace.

Community
  • 1
  • 1
MJ Vakili
  • 2,798
  • 1
  • 19
  • 25

1 Answers1

1

Use Assembly.GetCallingAssembly instead of Assembly.GetExecutingAssembly and you should get the ConsoleApplication1-Assembly.

You get all Namespaces of that Assembly, but it will sure contain ConsoleApplication1, but not only.

Patrik
  • 1,355
  • 12
  • 22
  • @patrickEchebrecht Thank you for your answer. but not answer in Asp.Net MVC . return Anonymously Hosted DynamicMethods . Can you help me? – MJ Vakili Apr 29 '15 at 08:56
  • No Sorry :-/ Ask a new question with the ASP.NET tag. Sure someone will be able to help. – Patrik Apr 29 '15 at 09:01