tellingmachine
tellingmachine

Reputation: 1085

Can I create my own attribute classes in PowerShell 2.0?

I was wondering whether you could create your own .NET Attribute classes for PowerShell and use them in scripts e.g.

[DebugAttribute=true]
function DoSomeThing()
{
"I don't run in Release mode"
}

Upvotes: 2

Views: 252

Answers (1)

Steven Murawski
Steven Murawski

Reputation: 11255

You should be able to create your own attributes, but only for certain purposes - specifically validation and argument transformation.

From the MSDN Docs:

Snap-ins cannot create custom attributes that derive directly from CmdletMetadataAttribute because there is no public constructor. However, snap-ins can derive custom attributes from the ValidateArgumentsAttribute and ArgumentTransformationAttribute classes.

I have yet to create a cmdlet attribute and try it in an advanced function though.

Upvotes: 1

Related Questions