Example #1
0
 protected override object NewDriveDynamicParameters()
 {
     try{
         WriteVerbose("TmxProvider::NewDriveDynamicParameters()");
         dynamicParameters =
             new RuntimeDefinedParameterDictionary();
         var atts1 = new Collection<Attribute>();
         var parameterAttribute1 = new ParameterAttribute {Mandatory = true};
         //ParameterAttribute parameterAttribute1 = new ParameterAttribute();
         //parameterAttribute1.Mandatory = true;
         //parameterAttribute2.ParameterSetName = "WindowNameParameterSet";
         atts1.Add(parameterAttribute1);
         var attr1 = new AllowEmptyStringAttribute();
         atts1.Add(attr1);
         dynamicParameters.Add(
             "windowName", 
             new RuntimeDefinedParameter(
                 "windowName", 
                 typeof(string), 
                 atts1));
         
         var atts2 = new Collection<Attribute>();
         var parameterAttribute2 = new ParameterAttribute {Mandatory = true};
         //ParameterAttribute parameterAttribute2 = new ParameterAttribute();
         //parameterAttribute2.Mandatory = true;
         //parameterAttribute2.ParameterSetName = "ProcessNameParameterSet";
         atts2.Add(parameterAttribute2);
         var attr2 = new AllowEmptyStringAttribute();
         atts2.Add(attr2);
         dynamicParameters.Add(
             "processName", 
             new RuntimeDefinedParameter(
                 "processName", 
                 typeof(string), 
                 atts2));
         
         var atts3 = new Collection<Attribute>();
         var parameterAttribute3 = new ParameterAttribute {Mandatory = true};
         //ParameterAttribute parameterAttribute3 = new ParameterAttribute();
         //parameterAttribute3.Mandatory = true;
         //parameterAttribute3.ParameterSetName = "ProcessIdParameterSet";
         atts3.Add(parameterAttribute3);
         var attr3 = new AllowEmptyStringAttribute();
         atts3.Add(attr3);
         dynamicParameters.Add(
             "processId", 
             new RuntimeDefinedParameter(
                 "processId", 
                 typeof(int), 
                 atts3));
         
         return dynamicParameters;
     }
     catch (Exception e) {
         WriteVerbose(e.Message);
         WriteVerbose("TmxProvider::NewDriveDynamicParameters()");
         return null;
     }
 }
Example #2
0
        /// <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;
            }
        }