Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Created March 10, 2015 20:59
Show Gist options
  • Save Jaykul/db1a254bdcbd4a14878b to your computer and use it in GitHub Desktop.
Save Jaykul/db1a254bdcbd4a14878b to your computer and use it in GitHub Desktop.
Playing with classes in PowerShell 5 (February Preview)
# In the real world, I'm trying to use Nancy.NancyModule, but for demo's sake, it can be this simple:
add-type @'
namespace Nancy
{
public abstract class NancyModule
{
protected NancyModule() { }
}
}
'@
# Use a ScriptBlock to keep the type definition and use in the same scope
&{
class SampleModule : Nancy.NancyModule {
SampleModule() {
}
}
[SampleModule]::new()
}
# Get this error
# an object comes out too ... but the WriteLine doesn't get written, of course,
# so I have no idea how the object was constructed ...
Cannot find an overload for "new" and the argument count: "0".
At line:3 char:24
+ SampleModule() {
+ ~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment