Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何测试IncludeExceptionDetailInFaults_C#_Wcf_Attributes_Servicebehavior - Fatal编程技术网

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
{ }
希望这对别人有帮助