How to use C# Code to List all Namespaces in .NetStandard Library in a .Net Standard Project

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 05:09:13

问题


How to use C# Code to List all Namespaces in .NetStandard Library 2.0 from within a .Net Standard Project.

This is the Code which gives Namspaces in netStandard Library is 0;

            foreach (AssemblyName fooAssemblyName in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
            {
                Assembly assembly = Assembly.Load(fooAssemblyName.FullName);
                var namespaces = assembly.GetTypes()
                    .Select(t => t.Namespace).Where(t => !string.IsNullOrEmpty(t))
                    .Distinct();
                int count = namespaces.Count();
                if (fooAssemblyName.Name == "netstandard")
                {
                    Console.WriteLine(count); // THIS GIVES 0 for .Net Standard Library
                }
            }

来源:https://stackoverflow.com/questions/59026604/how-to-use-c-sharp-code-to-list-all-namespaces-in-netstandard-library-in-a-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!