简体   繁体   中英

C# CodeDom generic add “out” parameter

I like to create a funktion which has a generic parameter:

public interface IInterfaceMethod< out T0> : where T0 : IInterface2

So i created a new CodeTypeParameter and added this as constraint. So how can i create the "out" value?

Thanks

You can only put the T0 generic type in "out" positions inside this interface:

  • As the data type of a getter-only property
  • As the data type of the return value of a method

You can not:

  • Use the type as the data type for a property with a setter
  • Use the type as the data type for a parameter (not even out parameters)

So this is an example of your interface:

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

while this is illegal:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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