red-gate / XmlDoc2CmdletDoc

Create cmdlet XML help files from XML doc comments
Other
63 stars 24 forks source link

Dynamic parameters support #26

Closed art-bel closed 7 years ago

art-bel commented 7 years ago

Description topics for dynamic parameters are not generated. I added code inserting parameters from nested classes of the cmdlet if it implements IDynamicParameters interface. In my situation it's enough to generate a correct help file. You can use it or make additional dynamic parameters metadata to support cmdlets implementing dynamic parameters. `

    public IEnumerable<Parameter> Parameters
    {
        get
        {
            IEnumerable<Parameter> members = CmdletType.GetMembers(BindingFlags.Instance | BindingFlags.Public)
                .Where(member => member.GetCustomAttributes<ParameterAttribute>().Any())
                .Select(member => new Parameter(CmdletType, member));

            if (typeof(IDynamicParameters).IsAssignableFrom(CmdletType) == true)
            {
                foreach (Type t in CmdletType.GetNestedTypes())
                {
                    IEnumerable<Parameter> tmp = t.GetMembers(BindingFlags.Instance | BindingFlags.Public)
                        .Where(member => member.GetCustomAttributes<ParameterAttribute>().Any())
                        .Select(member => new Parameter(t, member));

                    if ((tmp != null) && (tmp.Count() > 0))
                    {
                        members = members.Concat(tmp);
                    }
                }
            }

            return members;
        }
    }

`

ChrisLambrou commented 7 years ago

Hi! Thanks for this. I'm a little pressed for time, just at the moment, but I'll try to include this, along with some tests, on Friday and get it released shortly afterwards.

ChrisLambrou commented 7 years ago

Okay, I've been looking into dynamic parameters in a bit more detail, and it turns out that documenting them reliably is rather difficult. In theory the IDynamicParameters.GetDynamicParameters() method could return anything. The suggestion here would only work in the limited case where the cmdlet returns an instance of an inner class. I guess that's okay. XmlDoc2CmdletDoc is already a bit opinionated about how cmdlets are arranged in order for this tool to work, so I don't see this restriction as a particular problem.

ChrisLambrou commented 7 years ago

Shipped in v 0.2.5.