private Dictionary <string, CmdletHouse> LocateCmdlets() { Dictionary <string, CmdletHouse> cmdlets; if (!ScenarioContext.Current.TryGetValue(CmdTestingConstants.Cmdlets, out cmdlets)) { cmdlets = new Dictionary <string, CmdletHouse>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in assembly.GetTypes()) { if (typeof(Cmdlet).IsAssignableFrom(type)) { var cmdletAttribute = type.GetCustomAttribute(typeof(CmdletAttribute)).As <CmdletAttribute>(); if (cmdletAttribute.IsNotNull()) { string verb = cmdletAttribute.VerbName; string noun = cmdletAttribute.NounName; string name = verb + "-" + noun; var cmdletHouse = new CmdletHouse() { Type = type }; cmdlets.Add(name, cmdletHouse); // Locate all the parameter sets. foreach (var propertyInfo in type.GetProperties()) { var aliases = new List <string>(); // Get all the Aliases var paramAliases = propertyInfo.GetCustomAttributes(typeof(AliasAttribute)).Cast <AliasAttribute>(); if (paramAliases.Any()) { aliases.AddRange(paramAliases.SelectMany(a => a.AliasNames)); } // Get all the ParameterAttributes var paramAttribs = propertyInfo.GetCustomAttributes(typeof(ParameterAttribute)).Cast <ParameterAttribute>(); if (paramAttribs.Any()) { foreach (var paramAttrib in paramAttribs) { var parameterSet = paramAttrib.ParameterSetName; var parameterHouse = new ParameterHouse() { FullName = propertyInfo.Name, Property = propertyInfo, Parameter = paramAttrib, }; parameterHouse.Aliases.AddRange(aliases); ICollection <ParameterHouse> parameters; if (!cmdletHouse.ParameterSets.TryGetValue(parameterSet, out parameters)) { parameters = new List <ParameterHouse>(); cmdletHouse.ParameterSets.Add(parameterSet, parameters); } parameters.Add(parameterHouse); } } } } } } } ScenarioContext.Current.Add(CmdTestingConstants.Cmdlets, cmdlets); } return(cmdlets); }
private Dictionary<string, CmdletHouse> LocateCmdlets() { Dictionary<string, CmdletHouse> cmdlets; if (!ScenarioContext.Current.TryGetValue(CmdTestingConstants.Cmdlets, out cmdlets)) { cmdlets = new Dictionary<string, CmdletHouse>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in assembly.GetTypes()) { if (typeof(Cmdlet).IsAssignableFrom(type)) { var cmdletAttribute = type.GetCustomAttribute(typeof(CmdletAttribute)).As<CmdletAttribute>(); if (cmdletAttribute.IsNotNull()) { string verb = cmdletAttribute.VerbName; string noun = cmdletAttribute.NounName; string name = verb + "-" + noun; var cmdletHouse = new CmdletHouse() { Type = type }; cmdlets.Add(name, cmdletHouse); // Locate all the parameter sets. foreach (var propertyInfo in type.GetProperties()) { var aliases = new List<string>(); // Get all the Aliases var paramAliases = propertyInfo.GetCustomAttributes(typeof(AliasAttribute)).Cast<AliasAttribute>(); if (paramAliases.Any()) { aliases.AddRange(paramAliases.SelectMany(a => a.AliasNames)); } // Get all the ParameterAttributes var paramAttribs = propertyInfo.GetCustomAttributes(typeof(ParameterAttribute)).Cast<ParameterAttribute>(); if (paramAttribs.Any()) { foreach (var paramAttrib in paramAttribs) { var parameterSet = paramAttrib.ParameterSetName; var parameterHouse = new ParameterHouse() { FullName = propertyInfo.Name, Property = propertyInfo, Parameter = paramAttrib, }; parameterHouse.Aliases.AddRange(aliases); ICollection<ParameterHouse> parameters; if (!cmdletHouse.ParameterSets.TryGetValue(parameterSet, out parameters)) { parameters = new List<ParameterHouse>(); cmdletHouse.ParameterSets.Add(parameterSet, parameters); } parameters.Add(parameterHouse); } } } } } } } ScenarioContext.Current.Add(CmdTestingConstants.Cmdlets, cmdlets); } return cmdlets; }