Advertisement
Guest User

Untitled

a guest
May 25th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. // Specify the cmdlets that belong to this custom PowerShell snap-in.
  2. private Collection<CmdletConfigurationEntry> cmdlets;
  3. public override Collection<CmdletConfigurationEntry> Cmdlets
  4. {
  5. get
  6. {
  7. if (cmdlets == null)
  8. {
  9. string name = "fsharp-cmdlets, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
  10. Assembly fsharp = Assembly.Load(name);
  11.  
  12. Type cmdlet = typeof(Cmdlet);
  13. Type attribute = typeof(CmdletAttribute);
  14.  
  15. var have =
  16. fsharp.GetExportedTypes().Where(t => t.IsSubclassOf(cmdlet)).Select(
  17. t => new {Type = t, Attribs = t.GetCustomAttributes(attribute, false)}).
  18. Where(t => t.Attribs.Length > 0).
  19. Select(t =>
  20. {
  21. var attrib = t.Attribs[0] as CmdletAttribute;
  22. return new CmdletConfigurationEntry(
  23. // construct cmdlet name
  24. attrib.VerbName + "-" + attrib.NounName,
  25. t.Type, // cmdlet class type
  26. null // help filename for the cmdlet
  27. );
  28. }
  29. ).ToList();
  30.  
  31. cmdlets = new Collection<CmdletConfigurationEntry>(have);
  32.  
  33. }
  34. return cmdlets;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement