I have some WCF services and I have a list of service contracts (interfaces) in an assembly within a certain folder. I know the namespace and it will look something like this:
MyProject.Lib.ServiceContracts
I was hoping there was a way to be able to grab all files within that folder so I can iterate over each one and grab the attributes off of each method.
Is the above possible? If so, any advice on how to do the above?
Thanks for any assistance.
This should get you all such interfaces:
string directory = "/";
foreach (string file in Directory.GetFiles(directory,"*.dll"))
{
Assembly assembly = Assembly.LoadFile(file);
foreach (Type ti in assembly.GetTypes().Where(x=>x.IsInterface))
{
if(ti.GetCustomAttributes(true).OfType<ServiceContractAttribute>().Any())
{
// ....
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With