public static CSharpAttribute CreateODataTypeAttribute(string oDataTypeFullName, IEnumerable <string> subTypeFullNames = null) { if (oDataTypeFullName == null) { throw new ArgumentNullException(nameof(oDataTypeFullName)); } return(CSharpPropertyAttributeHelper.CreateODataTypeAttribute(oDataTypeFullName, subTypeFullNames ?? Array.Empty <string>())); }
/// <summary> /// Creates C# attributes from the information on a given cmdlet parameter /// </summary> /// <param name="parameter">The cmdlet parameter</param> /// <param name="parameterSets">The parameter sets that this parameter is a part of</param> /// <returns>The C# attributes.</returns> private static IEnumerable <CSharpAttribute> CreateAttributes(this CmdletParameter parameter, IEnumerable <CmdletParameterSet> parameterSets) { if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } if (parameterSets == null) { throw new ArgumentNullException(nameof(parameterSets)); } // ODataType attribute if (parameter.ODataTypeFullName != null) { yield return(CSharpPropertyAttributeHelper.CreateODataTypeAttribute(parameter.ODataTypeFullName, parameter.ODataSubTypeFullNames)); } // Selectable attribute if (parameter.IsSelectable) { yield return(CSharpPropertyAttributeHelper.CreateSelectableAttribute()); } // Expandable attribute if (parameter.IsExpandable) { yield return(CSharpPropertyAttributeHelper.CreateExpandableAttribute()); } // Sortable attribute if (parameter.IsSortable) { yield return(CSharpPropertyAttributeHelper.CreateSortableAttribute()); } // DerivedType attribute if (parameter.DerivedTypeName != null) { yield return(CSharpPropertyAttributeHelper.CreateDerivedTypeAttribute(parameter.DerivedTypeName)); } // ValidateSet attribute if (parameter.Documentation?.ValidValues != null && parameter.Documentation.ValidValues.Any()) { yield return(CSharpPropertyAttributeHelper.CreateValidateSetAttribute(parameter.Documentation.ValidValues)); } // ID attribute if (parameter.IsIdParameter) { yield return(CSharpPropertyAttributeHelper.CreateIdParameterAttribute()); } // Resource ID attribute if (parameter.IsResourceIdParameter) { yield return(CSharpPropertyAttributeHelper.CreateResourceIdParameterAttribute()); } // TypeCastParameter attribute if (parameter.IsTypeCastParameter) { yield return(CSharpPropertyAttributeHelper.CreateTypeCastParameterAttribute()); } // Parameter attribute if (parameter.IsPowerShellParameter) { // Aliases if (parameter.Aliases != null && parameter.Aliases.Any()) { yield return(CSharpPropertyAttributeHelper.CreateAliasAttribute(parameter.Aliases)); } // Validate not null if (parameter.ValidateNotNull) { yield return(CSharpPropertyAttributeHelper.CreateValidateNotNullAttribute()); } // Validate not null or empty if (parameter.ValidateNotNullOrEmpty) { yield return(CSharpPropertyAttributeHelper.CreateValidateNotNullOrEmptyAttribute()); } // ParameterSetSwitch attribute if (parameter.ParameterSetSelectorName != null) { yield return(CSharpPropertyAttributeHelper.CreateParameterSetSwitchAttribute(parameter.ParameterSetSelectorName)); } // AllowEmptyCollection attribute if (parameter.Type.IsArray) { yield return(CSharpPropertyAttributeHelper.CreateAllowEmptyCollectionAttribute()); } foreach (CmdletParameterSet parameterSet in parameterSets) { // Parameter attribute yield return(CSharpPropertyAttributeHelper.CreateParameterAttribute( parameterSet.Name, parameter.Mandatory, parameter.ValueFromPipeline, parameter.ValueFromPipelineByPropertyName, parameter.Documentation?.Descriptions?.FirstOrDefault())); } } }