Skip to main content
added 22 characters in body
Source Link
Keith Hill
  • 203.6k
  • 44
  • 370
  • 377

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()); }

public static string MyMethod<T>(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.

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.

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>(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.

Source Link
Keith Hill
  • 203.6k
  • 44
  • 370
  • 377

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.