C# 如何测试IncludeExceptionDetailInFaults
我可以检查是否设置了以下行为:C# 如何测试IncludeExceptionDetailInFaults,c#,wcf,attributes,servicebehavior,C#,Wcf,Attributes,Servicebehavior,我可以检查是否设置了以下行为: Attribute.GetCustomAttribute(typeof(MyService), typeof(ServiceBehavior)) 如何检查ServiceBehavior属性中是否定义和设置了特定属性?例如,IncludeExceptionDetailInFaults: [ServiceBehavior(IncludeExceptionDetailInFaults = true)] 实际上很简单,我需要强制转换属性,然后检查属性: Attribu
Attribute.GetCustomAttribute(typeof(MyService), typeof(ServiceBehavior))
如何检查ServiceBehavior属性中是否定义和设置了特定属性?例如,IncludeExceptionDetailInFaults:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
实际上很简单,我需要强制转换属性,然后检查属性:
Attribute behavior = Attribute.GetCustomAttribute(myService.GetType(), typeof(ServiceBehaviorAttribute));
if (behavior != null)
{
if (!((ServiceBehaviorAttribute)behavior).IncludeExceptionDetailInFaults)
{
throw new Exception(); // or whatever
}
}
该服务将类似于:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyService
{ }
希望这对别人有帮助