I typically use PowerShell as my prototyping tool for most new systems, and this almost always involves writing cmdlets (think of them as plugins) in C#; these .NET assemblies import into a PowerShell session and act as if they are built into the system.
Almost all cmdlets pass around .NET objects where they can be viewed and manipulated, but some fields might be public even though we don't want them to show up when a user queries them them.
If you use the [Hidden] attribute to adorn a property, it will still be available for the user to access explicitly, but will not show up by default when looking at that object.
using System.Management.Automation; // required for HiddenAttribute ... public class MyConfig { public string Username { get; set; } [Hidden] public string Password { get; set; } public string Server { get; set; } ... }
Now, if this config object is inspected by the user, it will omit the Password property from view.
Note - it's a poor security practice to tote passwords around in cleartext, which is exactly what the above example uses: it's better to use a SecureString (in the System.Security assembly), but this is far more tedious, is overkill in many circumstances, and would obscure the point of this post.
In any case, the SecureString would probably want to be hidden as well, because there's nothing there for the user to see, and it would just clutter the output, so the [Hidden] attribute would still be used here.
Comments