Calling generic static method in PowerShell

前端 未结 5 914
温柔的废话
温柔的废话 2020-12-05 23:47

How do you call a generic static method of a custom class in Powershell?

Given the following class:

public class Sample
{
    public static string My         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 00:23

    This is a limitation of PowerShell and can't be done directly in PowerShell V1 or V2 AFAIK.

    BTW your generic method isn't really generic. Shouldn't it be:

    public static string MyMethod(T anArgument)
    { 
       return string.Format( "Generic type is {0} with argument {1}", 
                             typeof(T), anArgument.ToString()); 
    } 
    

    If you own this code and want to use it from PowerShell, avoid generic methods or write a non-generic C# wrapper method.

提交回复
热议问题