Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Specify the cmdlets that belong to this custom PowerShell snap-in.
- private Collection<CmdletConfigurationEntry> cmdlets;
- public override Collection<CmdletConfigurationEntry> Cmdlets
- {
- get
- {
- if (cmdlets == null)
- {
- string name = "fsharp-cmdlets, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
- Assembly fsharp = Assembly.Load(name);
- Type cmdlet = typeof(Cmdlet);
- Type attribute = typeof(CmdletAttribute);
- var have =
- fsharp.GetExportedTypes().Where(t => t.IsSubclassOf(cmdlet)).Select(
- t => new {Type = t, Attribs = t.GetCustomAttributes(attribute, false)}).
- Where(t => t.Attribs.Length > 0).
- Select(t =>
- {
- var attrib = t.Attribs[0] as CmdletAttribute;
- return new CmdletConfigurationEntry(
- // construct cmdlet name
- attrib.VerbName + "-" + attrib.NounName,
- t.Type, // cmdlet class type
- null // help filename for the cmdlet
- );
- }
- ).ToList();
- cmdlets = new Collection<CmdletConfigurationEntry>(have);
- }
- return cmdlets;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement