Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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# ServiceBehavior属性是否由其他类继承?_C#_Wcf_Inheritance_Attributes - Fatal编程技术网

C# ServiceBehavior属性是否由其他类继承?

C# ServiceBehavior属性是否由其他类继承?,c#,wcf,inheritance,attributes,C#,Wcf,Inheritance,Attributes,我有几个WCF服务,这些服务共享一些常用方法。因此,我用这些方法创建了一个基类(不是WCF服务),并使所有WCF服务都继承自这个类。大概是这样的: [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)] public abstract class BaseService 以及其中一项WCF服务: public clas

我有几个WCF服务,这些服务共享一些常用方法。因此,我用这些方法创建了一个基类(不是WCF服务),并使所有WCF服务都继承自这个类。大概是这样的:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
    public abstract class BaseService
以及其中一项WCF服务:

public class ExampleService : BaseService, IExampleService
    {

我正在使用ServiceBehavior属性设置ConcurrencyMode和InstanceContextMode的值,我的问题是:使用ServiceBehavior属性标记基类,并期望所有服务继承ServiceBehavior属性的值是正确的,还是应该逐个标记所有WCF服务?

是,ServiceBehavior属性继承到子类,因为“ServiceBehaviorAttribute”类具有AttributeUsage属性,该属性不会将“继承的”值设置为False

“继承”的默认值在“AttributeUsageAttribute”类中为True


一个简单的例子是在抽象类中设置Namespace属性,并查看wsdl中反映的属性。

为什么不查看文档或检查该属性上的
AttributeUsage
?因为我在ServiceBehavior文档中没有找到任何关于继承的内容,我不知道如何检查属性上的属性。但是谢谢你的RTFM回答。非常有用。我想你根本没有理解我的问题,我完全理解。
AttributeUsage
仅指定
,因此未设置
继承的
属性,默认为false。我的意思是你应该学习这个属性(
AttributeUsage
)是如何工作的。对不起,我想我遗漏了一些东西。如果属性ussage只指定类,而我的BaseService类是一个抽象类(不是接口)。。你为什么这么说?奇怪的是默认值是真的+1澄清。@如果你认为继承是一种“是”的关系,那么为什么<>代码>长颈鹿< /代码>继承了所有的<代码>动物< /代码>属性?