On my website. I have added a class file in App_Code containing 5 public classes into one NameSpace.
I want to get all class names containing in a particular namespace.
In default.aspx.cs file i have added.
var q = from t in Assembly.GetExecutingAssembly().GetTypes()
where t.IsClass && t.Namespace == "Sample"
q.ToList().ForEach(t => Console.WriteLine(t.Name));
But I didn’t find Sample namespace in Assembly.GetExecutingAssembly().GetTypes()
how do I access the 'Sample' namespce in above code?
Thanks
I think the problem here might be due to the fact that this code is being executed in a temporary assembly created from your codebehind files.
To check this:
var q = from t in Assembly.GetExecutingAssembly().GetTypes()
where t.IsClass
select t;
q.ToList().ForEach(t => Console.WriteLine(t.Namespace));
typeof(Sample.Class1).Assemblyor… just read @Darin’s answer… I must learn to type faster!