Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherited Parameter attributes should not be used #34

Open
anywherepilot opened this issue Apr 11, 2017 · 0 comments
Open

Inherited Parameter attributes should not be used #34

anywherepilot opened this issue Apr 11, 2017 · 0 comments
Assignees
Labels

Comments

@anywherepilot
Copy link

anywherepilot commented Apr 11, 2017

If you have a hierarchy of inheriting classes with virtual and overridden properties, only the ones applied to the overridden property must be taken into account, including none if the overridden property has no such attributes. This is the way PowerShell itself does it. From the PowerShell source CompiledCommandParameter.cs:

// We do not want to get the inherited custom attributes, only the attributes exposed
// directly on the member
var memberAttributes = member.GetCustomAttributes(false);

In our setup we encountered three problems with this:

  1. Parameters which are in AllParameterSets in the base class but only in specific ones in the derived class, are documented as if they are everywhere, while they are not in PowerShell.
  2. Parameters which are mandatory in the base class and not mandatory in the derived class are documented as if they are mandatory, while they are not in PowerShell.
  3. Parameters which are hidden in the derived class by overriding the property without an attribute, are documented as if they exist, while they are not in PowerShell.

The fix could be as simple as adding 'false' into the calls to GetCustomAttributes, similarly to how PowerShell does it internally. For the Mandatory issue, it may also be necessary to change this code to allow for specific parameter sets to override the value from AllParameterSets:

public bool IsRequired(string parameterSetName)
{
    return GetAttributes(parameterSetName).Any(attr => attr.Mandatory);
}

Thank you for looking into this. Please let me know whether you agree with this analysis and proposed implementation.

@ChrisLambrou ChrisLambrou self-assigned this Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants