【问题标题】:How do you apply a .net attribute to a return type如何将 .net 属性应用于返回类型
【发布时间】:2008-09-25 04:19:40
【问题描述】:

如何将 MarshalAsAttribute 应用于下面代码的返回类型?

public ISomething Foo()
{
    return new MyFoo();
}

【问题讨论】:

    标签: c# .net attributes return-type


    【解决方案1】:

    根据http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute.aspx

    [return: MarshalAs(<your marshal type>)]
    public ISomething Foo()
    {
        return new MyFoo();
    }
    

    【讨论】:

      【解决方案2】:
      [return:MarshalAs]
      public ISomething Foo()
      {
          return new MyFoo();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-04-02
        • 2021-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多