1

Very simple question:

In all of the examples I've seen, cmdlets never take advantage of auto-implemented properties for the cmdlet parameters, is there any genuine reason for not using auto-implemented properties?

1 Answer 1

2

I don't think there's any reason why you couldn't use auto-implemented properties. I have and it seems to work fine. My guess would be that a lot of example code was just written pre-C# 3.0 and they had to do it by hand.

Sign up to request clarification or add additional context in comments.

6 Comments

Not saying you are wrong, I did think about this myself, but .. PowerShell was introduced in 2006, C# 3.0 was introduced in 2007, is it really the case that ALL examples that I've come across are from that one year period and no more examples were ever produced post 2007? Sounds quite unlikely. Again, not saying it's not possible.
I agree with mike z because when PowerShell 2.0 added the ability to write advanced functions (functions that behave more like binary cmdlets), the need to use C# to write cmdlets diminished significantly.
@cogumel0 If it ain't broke, don't fix it. Why rewrite sample code that still works. Also, old habits die hard. I suspect a lot people who wrote code after 2007 still manually implemented properties. If you want examples, PowerShell Community Extensions uses auto-properties a lot.
I think this is mostly the reason, but I still run across some folks that haven't seen auto-implemented properties.
Actually can think of one reason not to use auto-implemented properties - default values. As described here codeproject.com/Tips/310476/… you need a backing variable.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.