繁体   English   中英

C#CodeDom泛型添加“ out”参数

[英]C# CodeDom generic add “out” parameter

我喜欢创建一个具有通用参数的功能:

公共接口IInterfaceMethod < out T0>:其中T0:IInterface2

所以我创建了一个新的CodeTypeParameter并将其添加为约束。 那么如何创建“输出”值?

谢谢

您只能将T0泛型类型放在此接口内的“ out”位置:

  • 作为仅获取属性的数据类型
  • 作为方法的返回值的数据类型

你不能:

  • 使用类型作为带有setter的属性的数据类型
  • 使用类型为数据类型的参数(甚至没有out参数)

因此,这是您的界面的示例:

public interface IInterfaceMethod<out T0>
    where T0 : IInterface2
{
    T0 GetterOnly { get; }
    T0 MethodReturnValue();
}

虽然这是非法的:

public interface IInterfaceMethod<out T0>
    where T0 : IInterface2
{
    T0 GetterAndSetter { get; set; }
    void MethodParameter(T0 value);
    void MethodOutParameter(out T0 value);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM