/// <summary> /// Get the output types specified on this provider for the cmdlet requested. /// </summary> internal void GetOutputTypes(string cmdletname, List<PSTypeName> listToAppend) { if (_providerOutputType == null) { _providerOutputType = new Dictionary<string, List<PSTypeName>>(); foreach (OutputTypeAttribute outputType in ImplementingType.GetCustomAttributes<OutputTypeAttribute>(false)) { if (string.IsNullOrEmpty(outputType.ProviderCmdlet)) { continue; } List<PSTypeName> l; if (!_providerOutputType.TryGetValue(outputType.ProviderCmdlet, out l)) { l = new List<PSTypeName>(); _providerOutputType[outputType.ProviderCmdlet] = l; } l.AddRange(outputType.Type); } } List<PSTypeName> cmdletOutputType = null; if (_providerOutputType.TryGetValue(cmdletname, out cmdletOutputType)) { listToAppend.AddRange(cmdletOutputType); } }
public MethodInfo GetMethod(Type[] genericTypes) { foreach (var methodInfo in ImplementingType.GetMethods(BindingFlags.Public | BindingFlags.Static)) { var parameters = methodInfo.GetParameters(); if (parameters.Length != 2) { continue; } if (parameters[1].ParameterType != typeof(IContext)) { continue; } var genericArguments = methodInfo.GetGenericArguments(); if (genericArguments.Length != genericTypes.Length) { continue; } return(methodInfo.MakeGenericMethod(genericTypes)); } throw new MissingMethodException(ImplementingType.Name, "Implementation"); }
/// <summary> /// Defines a command. /// </summary> /// <param name="key">Value that was used / can be used to select this command.</param> /// <param name="implementingType">Type that implements this command.</param> public CommandDefinition(object key, Type implementingType) { Key = key; ImplementingType = implementingType ?? throw new ArgumentNullException(nameof(implementingType)); if (!typeof(ICommand).GetTypeInfo().IsAssignableFrom(ImplementingType.GetTypeInfo())) { throw new InvalidCommandException($"Type {ImplementingType.FullName} does not implement required {typeof(ICommand).FullName} interface."); } }
public MethodInfo GetMethod() { foreach (var methodInfo in ImplementingType.GetMethods(BindingFlags.Public | BindingFlags.Static)) { var parameters = methodInfo.GetParameters(); if (parameters.Length == 2 && parameters[1].ParameterType == typeof(IContext)) { if (parameters[0].ParameterType == BehaviorType) { return(methodInfo); } if (parameters[0].ParameterType.IsGenericType && BehaviorType.IsGenericType) { if (parameters[0].ParameterType.GetGenericTypeDefinition() == BehaviorType.GetGenericTypeDefinition()) { return(methodInfo); } } } } throw new MissingMethodException(ImplementingType.Name, "Implementation"); }