internal override IEnumerable <PSTypeName> GetInferredType(CompletionContext context) { TypeConstraintAst iteratorVariable0 = this.Attributes.OfType <TypeConstraintAst>().FirstOrDefault <TypeConstraintAst>(); if (iteratorVariable0 != null) { Type reflectionType = iteratorVariable0.TypeName.GetReflectionType(); if (reflectionType != null) { yield return(new PSTypeName(reflectionType)); } else { yield return(new PSTypeName(iteratorVariable0.TypeName.FullName)); } } IEnumerator <AttributeAst> enumerator = this.Attributes.OfType <AttributeAst>().GetEnumerator(); while (enumerator.MoveNext()) { AttributeAst current = enumerator.Current; PSTypeNameAttribute attribute = null; try { attribute = current.GetAttribute() as PSTypeNameAttribute; } catch (RuntimeException) { } if (attribute != null) { yield return(new PSTypeName(attribute.PSTypeName)); } } }
/// <summary> /// Processes the Attribute metadata to generate a CompiledCommandAttribute. /// </summary> /// <exception cref="MetadataException"> /// If the attribute is a parameter attribute and another parameter attribute /// has been processed with the same parameter-set name. /// </exception> private void ProcessAttribute( string memberName, Attribute attribute, ref Collection <ValidateArgumentsAttribute> validationAttributes, ref Collection <ArgumentTransformationAttribute> argTransformationAttributes, ref string[] aliases) { if (attribute == null) { return; } CompiledAttributes.Add(attribute); // Now process the attribute based on it's type if (attribute is ParameterAttribute paramAttr) { ProcessParameterAttribute(memberName, paramAttr); return; } ValidateArgumentsAttribute validateAttr = attribute as ValidateArgumentsAttribute; if (validateAttr != null) { if (validationAttributes == null) { validationAttributes = new Collection <ValidateArgumentsAttribute>(); } validationAttributes.Add(validateAttr); if ((attribute is ValidateNotNullAttribute) || (attribute is ValidateNotNullOrEmptyAttribute)) { this.CannotBeNull = true; } return; } AliasAttribute aliasAttr = attribute as AliasAttribute; if (aliasAttr != null) { if (aliases == null) { aliases = aliasAttr.aliasNames; } else { var prevAliasNames = aliases; var newAliasNames = aliasAttr.aliasNames; aliases = new string[prevAliasNames.Length + newAliasNames.Length]; Array.Copy(prevAliasNames, aliases, prevAliasNames.Length); Array.Copy(newAliasNames, 0, aliases, prevAliasNames.Length, newAliasNames.Length); } return; } ArgumentTransformationAttribute argumentAttr = attribute as ArgumentTransformationAttribute; if (argumentAttr != null) { if (argTransformationAttributes == null) { argTransformationAttributes = new Collection <ArgumentTransformationAttribute>(); } argTransformationAttributes.Add(argumentAttr); return; } AllowNullAttribute allowNullAttribute = attribute as AllowNullAttribute; if (allowNullAttribute != null) { this.AllowsNullArgument = true; return; } AllowEmptyStringAttribute allowEmptyStringAttribute = attribute as AllowEmptyStringAttribute; if (allowEmptyStringAttribute != null) { this.AllowsEmptyStringArgument = true; return; } AllowEmptyCollectionAttribute allowEmptyCollectionAttribute = attribute as AllowEmptyCollectionAttribute; if (allowEmptyCollectionAttribute != null) { this.AllowsEmptyCollectionArgument = true; return; } ObsoleteAttribute obsoleteAttr = attribute as ObsoleteAttribute; if (obsoleteAttr != null) { ObsoleteAttribute = obsoleteAttr; return; } PSTypeNameAttribute psTypeNameAttribute = attribute as PSTypeNameAttribute; if (psTypeNameAttribute != null) { this.PSTypeName = psTypeNameAttribute.PSTypeName; } }