如何在部分接口上声明的方法中添加属性? [英] How to add an attribute to a method declared on partial interface?

查看:108
本文介绍了如何在部分接口上声明的方法中添加属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向部分接口上声明的方法添加属性?

我在文件上有此代码

How to add an attribute to a method declared on partial interface?

Ihave this code on a file

using System;
using System.Net.Security;
using WCF = global::System.ServiceModel;

namespace CMAWCF.ServiceContracts
{
    public partial interface IMyServiceServiceContract
    {
        [WCF::TransactionFlow(WCF::TransactionFlowOption.Mandatory)]
        void DoSomething(CMAWCF.MessageContracts.RequestDoSomething
                             request);
    }
}



并且此代码是由工具在同一项目中的其他文件上生成的



and this code was generated by a tool on other file on the same project

using System;
using System.Net.Security;
using WCF = global::System.ServiceModel;

namespace CMAWCF.ServiceContracts
{
    public partial interface IMyServiceServiceContract
    {
        //... More methods
        [WCF::FaultContract(typeof(CMAWCF.FaultContracts.DefaultFaultContract))]
	[WCF::OperationContract(IsTerminating = false, IsInitiating =
        true, IsOneWay = false, AsyncPattern = false, Action = "DoSomething",
        ProtectionLevel = ProtectionLevel.None)]
        void DoSomething(CMAWCF.MessageContracts.RequestDoSomething
                             request);
        //... More methods
    }
}



但是我遇到了一个错误:

类型"CMAWCF.ServiceContracts.IMyServiceServiceContract"已经定义了具有相同参数类型的名为"DoSomething"的成员

我如何获得这样的输出:



But I got an error:

Type ''CMAWCF.ServiceContracts.IMyServiceServiceContract'' already defines a member called ''DoSomething'' with the same parameter types

How can I get an output like this:

using System;
using System.Net.Security;
using WCF = global::System.ServiceModel;

namespace CMAWCF.ServiceContracts
{
    public partial interface IMyServiceServiceContract
    {
        [WCF::TransactionFlow(WCF::TransactionFlowOption.Mandatory)]
        [WCF::FaultContract(typeof(CMAWCF.FaultContracts.DefaultFaultContract))]
	[WCF::OperationContract(IsTerminating = false, IsInitiating =
        true, IsOneWay = false, AsyncPattern = false, Action = "DoSomething",
        ProtectionLevel = ProtectionLevel.None)]
        void DoSomething(CMAWCF.MessageContracts.RequestDoSomething
                             request);
    }
}



我发现了一些



I found some discussion about it, but nothing solid. Any idea? thanks in advance.

推荐答案

此问题与属性无关,或……与任何问题均无关.部分语法不是很多语法.它非常简单,用于在两个或多个代码文本片段(通常在不同文件中)中定义某种类型.没别的.它不允许您重复任何声明.您的方法只能使用属性声明一次.如果这是您的工具,请对其进行修复.如果没有,请不要使用它,或者在最坏的情况下,请仅在正确工作的地方使用它.

—SA
This problem has nothing to do with attributes or… it does not have to do with anything. Partial syntax is not very much of syntax; it''s something very simple, used to define some type in two or more fragments of text of the code, typically in different files. And nothing else. It does not allow you to repeat any declaration. Your method should be declared only once, with the attribute. If this is your tool, fix it. If not, do not use it, or, in worst case, around by using it only where it works correctly.

—SA


这篇关于如何在部分接口上声明的方法中添加属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆