I have a need to access common properties within my class functions and, unfortunately, outside my class in other functions.
For example
Class Myclass { [Void]my_function(){ $file_location = "$myvar" } } properties { # some props $myvar = "somefile.txt" } function do_things{ echo $myvar } When I attempt to access $myvar within my_function as part of the class, I get a parsing error "variable is not defined in the method" which makes sense as the variable isn't declared in the class, but I would imagine things in a properties block would be usable.
I'm hoping there is something I"m not aware of and haven't been able to find in the documentation that allows me to do this. It seems rather silly that I can't use properties within my class functions.
My current (unfavorable) solution is to have my class inherit from another class that just has a bunch of static variables defined in it since you can access those anywhere else in the script by doing [MyOtherClass]::static_variable_name. This just isn't how I'd prefer to do it.
Please advise
$file_location = Get-Variable myvar -ValueOnly