首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何测试IncludeExceptionDetailInFaults

如何测试IncludeExceptionDetailInFaults
EN

Stack Overflow用户
提问于 2015-11-14 03:27:50
回答 1查看 77关注 0票数 0

我可以使用以下命令检查行为是否已设置:

代码语言:javascript
复制
Attribute.GetCustomAttribute(typeof(MyService), typeof(ServiceBehavior))

如何检查是否在ServiceBehavior属性中定义和设置了特定属性?例如,IncludeExceptionDetailInFaults:

代码语言:javascript
复制
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
EN

回答 1

Stack Overflow用户

发布于 2015-11-14 04:29:11

实际上这很简单,我需要强制转换属性,然后检查属性:

代码语言:javascript
复制
Attribute behavior = Attribute.GetCustomAttribute(myService.GetType(), typeof(ServiceBehaviorAttribute));
if (behavior != null)
{
    if (!((ServiceBehaviorAttribute)behavior).IncludeExceptionDetailInFaults)
    {
        throw new Exception(); // or whatever
    }
}

该服务将类似于:

代码语言:javascript
复制
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyService
{ }

希望这对某些人有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33700386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档