Exemplo n.º 1
0
        internal string GetProxyParameterData(string prefix, string paramNameOverride, bool isProxyForCmdlet)
        {
            StringBuilder builder = new StringBuilder();

            if ((this.parameterSets != null) && isProxyForCmdlet)
            {
                foreach (string str in this.parameterSets.Keys)
                {
                    string proxyParameterData = this.parameterSets[str].GetProxyParameterData();
                    if (!string.IsNullOrEmpty(proxyParameterData) || !str.Equals("__AllParameterSets"))
                    {
                        string str3 = "";
                        builder.Append(prefix);
                        builder.Append("[Parameter(");
                        if (!str.Equals("__AllParameterSets"))
                        {
                            builder.AppendFormat(CultureInfo.InvariantCulture, "ParameterSetName='{0}'", new object[] { CommandMetadata.EscapeSingleQuotedString(str) });
                            str3 = ", ";
                        }
                        if (!string.IsNullOrEmpty(proxyParameterData))
                        {
                            builder.Append(str3);
                            builder.Append(proxyParameterData);
                        }
                        builder.Append(")]");
                    }
                }
            }
            if ((this.aliases != null) && (this.aliases.Count > 0))
            {
                StringBuilder builder2 = new StringBuilder();
                string        str4     = "";
                foreach (string str5 in this.aliases)
                {
                    builder2.AppendFormat(CultureInfo.InvariantCulture, "{0}'{1}'", new object[] { str4, CommandMetadata.EscapeSingleQuotedString(str5) });
                    str4 = ",";
                }
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[Alias({1})]", new object[] { prefix, builder2.ToString() });
            }
            if ((this.attributes != null) && (this.attributes.Count > 0))
            {
                foreach (Attribute attribute in this.attributes)
                {
                    string proxyAttributeData = this.GetProxyAttributeData(attribute, prefix);
                    if (!string.IsNullOrEmpty(proxyAttributeData))
                    {
                        builder.Append(proxyAttributeData);
                    }
                }
            }
            if (this.SwitchParameter)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[{1}]", new object[] { prefix, "switch" });
            }
            else if (this.parameterType != null)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[{1}]", new object[] { prefix, ToStringCodeMethods.Type(this.parameterType, false) });
            }
            builder.AppendFormat(CultureInfo.InvariantCulture, "{0}${{{1}}}", new object[] { prefix, CommandMetadata.EscapeVariableName(string.IsNullOrEmpty(paramNameOverride) ? this.name : paramNameOverride) });
            return(builder.ToString());
        }
Exemplo n.º 2
0
        internal string GetProxyParameterData()
        {
            StringBuilder builder = new StringBuilder();
            string        str     = "";

            if (this.isMandatory)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}Mandatory=$true", new object[] { str });
                str = ", ";
            }
            if (this.position != -2147483648)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}Position={1}", new object[] { str, this.position });
                str = ", ";
            }
            if (this.valueFromPipeline)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}ValueFromPipeline=$true", new object[] { str });
                str = ", ";
            }
            if (this.valueFromPipelineByPropertyName)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}ValueFromPipelineByPropertyName=$true", new object[] { str });
                str = ", ";
            }
            if (this.valueFromRemainingArguments)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}ValueFromRemainingArguments=$true", new object[] { str });
                str = ", ";
            }
            if (!string.IsNullOrEmpty(this.helpMessage))
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "{0}HelpMessage='{1}'", new object[] { str, CommandMetadata.EscapeSingleQuotedString(this.helpMessage) });
                str = ", ";
            }
            return(builder.ToString());
        }
Exemplo n.º 3
0
        private string GetProxyAttributeData(Attribute attrib, string prefix)
        {
            ValidateLengthAttribute attribute = attrib as ValidateLengthAttribute;

            if (attribute != null)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[ValidateLength({1}, {2})]", new object[] { prefix, attribute.MinLength, attribute.MaxLength }));
            }
            ValidateRangeAttribute attribute2 = attrib as ValidateRangeAttribute;

            if (attribute2 != null)
            {
                string str2;
                Type   type = attribute2.MinRange.GetType();
                if ((type == typeof(float)) || (type == typeof(double)))
                {
                    str2 = "{0}[ValidateRange({1:R}, {2:R})]";
                }
                else
                {
                    str2 = "{0}[ValidateRange({1}, {2})]";
                }
                return(string.Format(CultureInfo.InvariantCulture, str2, new object[] { prefix, attribute2.MinRange, attribute2.MaxRange }));
            }
            if (attrib is AllowNullAttribute)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[AllowNull()]", new object[] { prefix }));
            }
            if (attrib is AllowEmptyStringAttribute)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[AllowEmptyString()]", new object[] { prefix }));
            }
            if (attrib is AllowEmptyCollectionAttribute)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[AllowEmptyCollection()]", new object[] { prefix }));
            }
            ValidatePatternAttribute attribute6 = attrib as ValidatePatternAttribute;

            if (attribute6 != null)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[ValidatePattern('{1}')]", new object[] { prefix, CommandMetadata.EscapeSingleQuotedString(attribute6.RegexPattern) }));
            }
            ValidateCountAttribute attribute7 = attrib as ValidateCountAttribute;

            if (attribute7 != null)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[ValidateCount({1}, {2})]", new object[] { prefix, attribute7.MinLength, attribute7.MaxLength }));
            }
            if (attrib is ValidateNotNullAttribute)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[ValidateNotNull()]", new object[] { prefix }));
            }
            if (attrib is ValidateNotNullOrEmptyAttribute)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[ValidateNotNullOrEmpty()]", new object[] { prefix }));
            }
            ValidateSetAttribute attribute10 = attrib as ValidateSetAttribute;

            if (attribute10 != null)
            {
                StringBuilder builder = new StringBuilder();
                string        str3    = "";
                foreach (string str4 in attribute10.ValidValues)
                {
                    builder.AppendFormat(CultureInfo.InvariantCulture, "{0}'{1}'", new object[] { str3, CommandMetadata.EscapeSingleQuotedString(str4) });
                    str3 = ",";
                }
                return(string.Format(CultureInfo.InvariantCulture, "{0}[ValidateSet({1})]", new object[] { prefix, builder.ToString() }));
            }
            ValidateScriptAttribute attribute11 = attrib as ValidateScriptAttribute;

            if (attribute11 != null)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[ValidateScript({{ {1} }})]", new object[] { prefix, attribute11.ScriptBlock.ToString() }));
            }
            PSTypeNameAttribute attribute12 = attrib as PSTypeNameAttribute;

            if (attribute12 != null)
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0}[PSTypeName('{1}')]", new object[] { prefix, CommandMetadata.EscapeSingleQuotedString(attribute12.PSTypeName) }));
            }
            return(null);
        }
Exemplo n.º 4
0
        public PSObject NewTotalCount(ulong totalCount, double accuracy)
        {
            PSObject       obj2   = new PSObject(totalCount);
            string         script = string.Format(CultureInfo.CurrentCulture, "\r\n                    $totalCount = $this.PSObject.BaseObject\r\n                    switch ($this.Accuracy) {{\r\n                        {{ $_ -ge 1.0 }} {{ '{0}' -f $totalCount }}\r\n                        {{ $_ -le 0.0 }} {{ '{1}' -f $totalCount }}\r\n                        default          {{ '{2}' -f $totalCount }}\r\n                    }}\r\n                ", new object[] { CommandMetadata.EscapeSingleQuotedString(CommandBaseStrings.PagingSupportAccurateTotalCountTemplate), CommandMetadata.EscapeSingleQuotedString(CommandBaseStrings.PagingSupportUnknownTotalCountTemplate), CommandMetadata.EscapeSingleQuotedString(CommandBaseStrings.PagingSupportEstimatedTotalCountTemplate) });
            PSScriptMethod member = new PSScriptMethod("ToString", ScriptBlock.Create(script));

            obj2.Members.Add(member);
            accuracy = Math.Max(0.0, Math.Min(1.0, accuracy));
            PSNoteProperty property = new PSNoteProperty("Accuracy", accuracy);

            obj2.Members.Add(property);
            return(obj2);
        }