I can check if the behavior is set or not with:
Attribute.GetCustomAttribute(typeof(MyService), typeof(ServiceBehavior))
How do I check if a specific property is defined and set within the ServiceBehavior attribute? for example the IncludeExceptionDetailInFaults:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
Actually it was simple, I needed to cast the attribute and then check for the property:
Attribute behavior = Attribute.GetCustomAttribute(myService.GetType(), typeof(ServiceBehaviorAttribute));
if (behavior != null)
{
if (!((ServiceBehaviorAttribute)behavior).IncludeExceptionDetailInFaults)
{
throw new Exception(); // or whatever
}
}
The service would be something like:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyService
{ }
Hope this helps someone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.