示例#1
0
 private ParameterMetadata GetParameter(string parameterSetName, string objectModelParameterName, TypeMetadata parameterTypeMetadata, CmdletParameterMetadata parameterCmdletization, bool isValueFromPipeline, bool isValueFromPipelineByPropertyName)
 {
     string pSName;
     if ((parameterCmdletization != null) && !string.IsNullOrEmpty(parameterCmdletization.PSName))
     {
         pSName = parameterCmdletization.PSName;
     }
     else
     {
         pSName = objectModelParameterName;
     }
     ParameterMetadata metadata = new ParameterMetadata(pSName) {
         ParameterType = this.GetDotNetType(parameterTypeMetadata)
     };
     if (parameterTypeMetadata.ETSType != null)
     {
         metadata.Attributes.Add(new PSTypeNameAttribute(parameterTypeMetadata.ETSType));
     }
     if (parameterCmdletization != null)
     {
         if (parameterCmdletization.Aliases != null)
         {
             foreach (string str2 in parameterCmdletization.Aliases)
             {
                 if (!string.IsNullOrEmpty(str2))
                 {
                     metadata.Aliases.Add(str2);
                 }
             }
         }
         if (parameterCmdletization.AllowEmptyCollection != null)
         {
             metadata.Attributes.Add(new AllowEmptyCollectionAttribute());
         }
         if (parameterCmdletization.AllowEmptyString != null)
         {
             metadata.Attributes.Add(new AllowEmptyStringAttribute());
         }
         if (parameterCmdletization.AllowNull != null)
         {
             metadata.Attributes.Add(new AllowNullAttribute());
         }
         if (parameterCmdletization.ValidateCount != null)
         {
             int minLength = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateCount.Min, typeof(int), CultureInfo.InvariantCulture);
             int maxLength = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateCount.Max, typeof(int), CultureInfo.InvariantCulture);
             metadata.Attributes.Add(new ValidateCountAttribute(minLength, maxLength));
         }
         if (parameterCmdletization.ValidateLength != null)
         {
             int num3 = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateLength.Min, typeof(int), CultureInfo.InvariantCulture);
             int num4 = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateLength.Max, typeof(int), CultureInfo.InvariantCulture);
             metadata.Attributes.Add(new ValidateLengthAttribute(num3, num4));
         }
         if (parameterCmdletization.ValidateNotNull != null)
         {
             metadata.Attributes.Add(new ValidateNotNullAttribute());
         }
         if (parameterCmdletization.ValidateNotNullOrEmpty != null)
         {
             metadata.Attributes.Add(new ValidateNotNullOrEmptyAttribute());
         }
         if (parameterCmdletization.ValidateRange != null)
         {
             Type type2;
             Type parameterType = metadata.ParameterType;
             if (parameterType == null)
             {
                 type2 = typeof(string);
             }
             else
             {
                 type2 = parameterType.HasElementType ? parameterType.GetElementType() : parameterType;
             }
             object minRange = LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateRange.Min, type2, CultureInfo.InvariantCulture);
             object maxRange = LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateRange.Max, type2, CultureInfo.InvariantCulture);
             metadata.Attributes.Add(new ValidateRangeAttribute(minRange, maxRange));
         }
         if (parameterCmdletization.ValidateSet != null)
         {
             List<string> list = new List<string>();
             foreach (string str3 in parameterCmdletization.ValidateSet)
             {
                 list.Add(str3);
             }
             metadata.Attributes.Add(new ValidateSetAttribute(list.ToArray()));
         }
     }
     int position = -2147483648;
     ParameterSetMetadata.ParameterFlags flags = 0;
     if (parameterCmdletization != null)
     {
         if (!string.IsNullOrEmpty(parameterCmdletization.Position))
         {
             position = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.Position, typeof(int), CultureInfo.InvariantCulture);
         }
         if (parameterCmdletization.IsMandatorySpecified && parameterCmdletization.IsMandatory)
         {
             flags |= ParameterSetMetadata.ParameterFlags.Mandatory;
         }
     }
     if (isValueFromPipeline)
     {
         flags |= ParameterSetMetadata.ParameterFlags.ValueFromPipeline;
     }
     if (isValueFromPipelineByPropertyName)
     {
         flags |= ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName;
     }
     metadata.ParameterSets.Add(parameterSetName, new ParameterSetMetadata(position, flags, null));
     return metadata;
 }
示例#2
0
 private void Write9_CmdletParameterMetadata(string n, string ns, CmdletParameterMetadata o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType)
         {
             Type type = o.GetType();
             if (type != typeof(CmdletParameterMetadata))
             {
                 if (type == typeof(CmdletParameterMetadataForGetCmdletParameter))
                 {
                     this.Write10_Item(n, ns, (CmdletParameterMetadataForGetCmdletParameter) o, isNullable, true);
                     return;
                 }
                 if (type == typeof(CmdletParameterMetadataForGetCmdletFilteringParameter))
                 {
                     this.Write11_Item(n, ns, (CmdletParameterMetadataForGetCmdletFilteringParameter) o, isNullable, true);
                     return;
                 }
                 if (type == typeof(CmdletParameterMetadataForStaticMethodParameter))
                 {
                     this.Write8_Item(n, ns, (CmdletParameterMetadataForStaticMethodParameter) o, isNullable, true);
                     return;
                 }
                 if (type != typeof(CmdletParameterMetadataForInstanceMethodParameter))
                 {
                     throw base.CreateUnknownTypeException(o);
                 }
                 this.Write7_Item(n, ns, (CmdletParameterMetadataForInstanceMethodParameter) o, isNullable, true);
                 return;
             }
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType("CmdletParameterMetadata", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11");
         }
         if (o.IsMandatorySpecified)
         {
             base.WriteAttribute("IsMandatory", "", XmlConvert.ToString(o.IsMandatory));
         }
         string[] aliases = o.Aliases;
         if (aliases != null)
         {
             base.Writer.WriteStartAttribute(null, "Aliases", "");
             for (int i = 0; i < aliases.Length; i++)
             {
                 string str = aliases[i];
                 if (i != 0)
                 {
                     base.Writer.WriteString(" ");
                 }
                 base.WriteValue(str);
             }
             base.Writer.WriteEndAttribute();
         }
         base.WriteAttribute("PSName", "", o.PSName);
         base.WriteAttribute("Position", "", o.Position);
         this.Write1_Object("AllowEmptyCollection", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.AllowEmptyCollection, false, false);
         this.Write1_Object("AllowEmptyString", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.AllowEmptyString, false, false);
         this.Write1_Object("AllowNull", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.AllowNull, false, false);
         this.Write1_Object("ValidateNotNull", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.ValidateNotNull, false, false);
         this.Write1_Object("ValidateNotNullOrEmpty", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.ValidateNotNullOrEmpty, false, false);
         this.Write4_Item("ValidateCount", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.ValidateCount, false, false);
         this.Write5_Item("ValidateLength", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.ValidateLength, false, false);
         this.Write6_Item("ValidateRange", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", o.ValidateRange, false, false);
         string[] validateSet = o.ValidateSet;
         if (validateSet != null)
         {
             base.WriteStartElement("ValidateSet", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", null, false);
             for (int j = 0; j < validateSet.Length; j++)
             {
                 base.WriteElementString("AllowedValue", "http://schemas.microsoft.com/cmdlets-over-objects/2009/11", validateSet[j]);
             }
             base.WriteEndElement();
         }
         bool isMandatorySpecified = o.IsMandatorySpecified;
         base.WriteEndElement(o);
     }
 }
示例#3
0
 private CmdletParameterMetadata Read9_CmdletParameterMetadata(bool isNullable, bool checkType)
 {
     XmlQualifiedName type = checkType ? base.GetXsiType() : null;
     bool flag = false;
     if (isNullable)
     {
         flag = base.ReadNull();
     }
     if ((checkType && (type != null)) && ((type.Name != this.id11_CmdletParameterMetadata) || (type.Namespace != this.id2_Item)))
     {
         if ((type.Name == this.id12_Item) && (type.Namespace == this.id2_Item))
         {
             return this.Read10_Item(isNullable, false);
         }
         if ((type.Name == this.id13_Item) && (type.Namespace == this.id2_Item))
         {
             return this.Read11_Item(isNullable, false);
         }
         if ((type.Name == this.id18_Item) && (type.Namespace == this.id2_Item))
         {
             return this.Read8_Item(isNullable, false);
         }
         if ((type.Name != this.id17_Item) || (type.Namespace != this.id2_Item))
         {
             throw base.CreateUnknownTypeException(type);
         }
         return this.Read7_Item(isNullable, false);
     }
     if (flag)
     {
         return null;
     }
     CmdletParameterMetadata o = new CmdletParameterMetadata();
     string[] a = null;
     int index = 0;
     bool[] flagArray = new bool[13];
     while (base.Reader.MoveToNextAttribute())
     {
         if ((!flagArray[9] && (base.Reader.LocalName == this.id46_IsMandatory)) && (base.Reader.NamespaceURI == this.id4_Item))
         {
             o.IsMandatory = XmlConvert.ToBoolean(base.Reader.Value);
             o.IsMandatorySpecified = true;
             flagArray[9] = true;
         }
         else
         {
             if ((base.Reader.LocalName == this.id47_Aliases) && (base.Reader.NamespaceURI == this.id4_Item))
             {
                 string[] strArray2 = base.Reader.Value.Split(null);
                 for (int i = 0; i < strArray2.Length; i++)
                 {
                     a = (string[]) base.EnsureArrayIndex(a, index, typeof(string));
                     a[index++] = strArray2[i];
                 }
                 continue;
             }
             if ((!flagArray[11] && (base.Reader.LocalName == this.id48_PSName)) && (base.Reader.NamespaceURI == this.id4_Item))
             {
                 o.PSName = base.Reader.Value;
                 flagArray[11] = true;
             }
             else
             {
                 if ((!flagArray[12] && (base.Reader.LocalName == this.id49_Position)) && (base.Reader.NamespaceURI == this.id4_Item))
                 {
                     o.Position = base.CollapseWhitespace(base.Reader.Value);
                     flagArray[12] = true;
                     continue;
                 }
                 if (!base.IsXmlnsAttribute(base.Reader.Name))
                 {
                     base.UnknownNode(o, ":IsMandatory, :Aliases, :PSName, :Position");
                 }
             }
         }
     }
     base.Reader.MoveToElement();
     if (base.Reader.IsEmptyElement)
     {
         base.Reader.Skip();
         o.Aliases = (string[]) base.ShrinkArray(a, index, typeof(string), true);
         return o;
     }
     base.Reader.ReadStartElement();
     base.Reader.MoveToContent();
     int whileIterations = 0;
     int readerCount = base.ReaderCount;
     while ((base.Reader.NodeType != XmlNodeType.EndElement) && (base.Reader.NodeType != XmlNodeType.None))
     {
         if (base.Reader.NodeType == XmlNodeType.Element)
         {
             if ((!flagArray[0] && (base.Reader.LocalName == this.id54_AllowEmptyCollection)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.AllowEmptyCollection = this.Read1_Object(false, true);
                 flagArray[0] = true;
             }
             else if ((!flagArray[1] && (base.Reader.LocalName == this.id55_AllowEmptyString)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.AllowEmptyString = this.Read1_Object(false, true);
                 flagArray[1] = true;
             }
             else if ((!flagArray[2] && (base.Reader.LocalName == this.id56_AllowNull)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.AllowNull = this.Read1_Object(false, true);
                 flagArray[2] = true;
             }
             else if ((!flagArray[3] && (base.Reader.LocalName == this.id57_ValidateNotNull)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.ValidateNotNull = this.Read1_Object(false, true);
                 flagArray[3] = true;
             }
             else if ((!flagArray[4] && (base.Reader.LocalName == this.id58_ValidateNotNullOrEmpty)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.ValidateNotNullOrEmpty = this.Read1_Object(false, true);
                 flagArray[4] = true;
             }
             else if ((!flagArray[5] && (base.Reader.LocalName == this.id59_ValidateCount)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.ValidateCount = this.Read4_Item(false, true);
                 flagArray[5] = true;
             }
             else if ((!flagArray[6] && (base.Reader.LocalName == this.id60_ValidateLength)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.ValidateLength = this.Read5_Item(false, true);
                 flagArray[6] = true;
             }
             else if ((!flagArray[7] && (base.Reader.LocalName == this.id61_ValidateRange)) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 o.ValidateRange = this.Read6_Item(false, true);
                 flagArray[7] = true;
             }
             else if ((base.Reader.LocalName == this.id62_ValidateSet) && (base.Reader.NamespaceURI == this.id2_Item))
             {
                 if (!base.ReadNull())
                 {
                     string[] strArray3 = null;
                     int num5 = 0;
                     if (base.Reader.IsEmptyElement)
                     {
                         base.Reader.Skip();
                     }
                     else
                     {
                         base.Reader.ReadStartElement();
                         base.Reader.MoveToContent();
                         int num6 = 0;
                         int num7 = base.ReaderCount;
                         while ((base.Reader.NodeType != XmlNodeType.EndElement) && (base.Reader.NodeType != XmlNodeType.None))
                         {
                             if (base.Reader.NodeType == XmlNodeType.Element)
                             {
                                 if ((base.Reader.LocalName == this.id63_AllowedValue) && (base.Reader.NamespaceURI == this.id2_Item))
                                 {
                                     strArray3 = (string[]) base.EnsureArrayIndex(strArray3, num5, typeof(string));
                                     strArray3[num5++] = base.Reader.ReadElementString();
                                 }
                                 else
                                 {
                                     base.UnknownNode(null, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11:AllowedValue");
                                 }
                             }
                             else
                             {
                                 base.UnknownNode(null, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11:AllowedValue");
                             }
                             base.Reader.MoveToContent();
                             base.CheckReaderCount(ref num6, ref num7);
                         }
                         base.ReadEndElement();
                     }
                     o.ValidateSet = (string[]) base.ShrinkArray(strArray3, num5, typeof(string), false);
                 }
             }
             else
             {
                 base.UnknownNode(o, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11:AllowEmptyCollection, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:AllowEmptyString, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:AllowNull, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateNotNull, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateNotNullOrEmpty, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateCount, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateLength, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateRange, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateSet");
             }
         }
         else
         {
             base.UnknownNode(o, "http://schemas.microsoft.com/cmdlets-over-objects/2009/11:AllowEmptyCollection, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:AllowEmptyString, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:AllowNull, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateNotNull, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateNotNullOrEmpty, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateCount, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateLength, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateRange, http://schemas.microsoft.com/cmdlets-over-objects/2009/11:ValidateSet");
         }
         base.Reader.MoveToContent();
         base.CheckReaderCount(ref whileIterations, ref readerCount);
     }
     o.Aliases = (string[]) base.ShrinkArray(a, index, typeof(string), true);
     base.ReadEndElement();
     return o;
 }
示例#4
0
        private ParameterMetadata GetParameter(
            string parameterSetName,
            string objectModelParameterName,
            TypeMetadata parameterTypeMetadata,
            CmdletParameterMetadata parameterCmdletization,
            bool isValueFromPipeline,
            bool isValueFromPipelineByPropertyName)
        {
            string parameterName;
            if ((parameterCmdletization != null) && (!string.IsNullOrEmpty(parameterCmdletization.PSName)))
            {
                parameterName = parameterCmdletization.PSName;
            }
            else
            {
                parameterName = objectModelParameterName;
            }

            ParameterMetadata parameterMetadata = new ParameterMetadata(parameterName);
            parameterMetadata.ParameterType = GetDotNetType(parameterTypeMetadata);
            if (typeof(PSCredential).Equals(parameterMetadata.ParameterType))
            {
                parameterMetadata.Attributes.Add(new CredentialAttribute());
            }

            if (parameterTypeMetadata.ETSType != null)
            {
                parameterMetadata.Attributes.Add(new PSTypeNameAttribute(parameterTypeMetadata.ETSType));
            }

            if (parameterCmdletization != null)
            {
                if (parameterCmdletization.Aliases != null)
                {
                    foreach (string alias in parameterCmdletization.Aliases)
                    {
                        if (!string.IsNullOrEmpty(alias))
                        {
                            parameterMetadata.Aliases.Add(alias);
                        }
                    }
                }

                if (parameterCmdletization.AllowEmptyCollection != null)
                {
                    parameterMetadata.Attributes.Add(new AllowEmptyCollectionAttribute());
                }

                if (parameterCmdletization.AllowEmptyString != null)
                {
                    parameterMetadata.Attributes.Add(new AllowEmptyStringAttribute());
                }

                if (parameterCmdletization.AllowNull != null)
                {
                    parameterMetadata.Attributes.Add(new AllowNullAttribute());
                }

                if (parameterCmdletization.ValidateCount != null)
                {
                    int min = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateCount.Min, typeof(int), CultureInfo.InvariantCulture);
                    int max = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateCount.Max, typeof(int), CultureInfo.InvariantCulture);
                    parameterMetadata.Attributes.Add(new ValidateCountAttribute(min, max));
                }

                if (parameterCmdletization.ValidateLength != null)
                {
                    int min = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateLength.Min, typeof(int), CultureInfo.InvariantCulture);
                    int max = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateLength.Max, typeof(int), CultureInfo.InvariantCulture);
                    parameterMetadata.Attributes.Add(new ValidateLengthAttribute(min, max));
                }

                if (parameterCmdletization.Obsolete != null)
                {
                    string obsoleteMessage = parameterCmdletization.Obsolete.Message;
                    parameterMetadata.Attributes.Add(obsoleteMessage != null ? new ObsoleteAttribute(obsoleteMessage) : new ObsoleteAttribute());
                }

                if (parameterCmdletization.ValidateNotNull != null)
                {
                    parameterMetadata.Attributes.Add(new ValidateNotNullAttribute());
                }

                if (parameterCmdletization.ValidateNotNullOrEmpty != null)
                {
                    parameterMetadata.Attributes.Add(new ValidateNotNullOrEmptyAttribute());
                }

                if (parameterCmdletization.ValidateRange != null)
                {
                    Type parameterType = parameterMetadata.ParameterType;
                    Type elementType;
                    if (parameterType == null)
                    {
                        elementType = typeof(string);
                    }
                    else
                    {
                        elementType = parameterType.HasElementType ? parameterType.GetElementType() : parameterType;
                    }
                    object min = LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateRange.Min, elementType, CultureInfo.InvariantCulture);
                    object max = LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateRange.Max, elementType, CultureInfo.InvariantCulture);
                    parameterMetadata.Attributes.Add(new ValidateRangeAttribute(min, max));
                }

                if (parameterCmdletization.ValidateSet != null)
                {
                    List<string> allowedValues = new List<string>();
                    foreach (string allowedValue in parameterCmdletization.ValidateSet)
                    {
                        allowedValues.Add(allowedValue);
                    }
                    parameterMetadata.Attributes.Add(new ValidateSetAttribute(allowedValues.ToArray()));
                }
            }

            int position = int.MinValue;
            ParameterSetMetadata.ParameterFlags parameterFlags = 0;
            if (parameterCmdletization != null)
            {
                if (!string.IsNullOrEmpty(parameterCmdletization.Position))
                {
                    position = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.Position, typeof(int), CultureInfo.InvariantCulture);
                }

                if (parameterCmdletization.IsMandatorySpecified && parameterCmdletization.IsMandatory)
                {
                    parameterFlags |= ParameterSetMetadata.ParameterFlags.Mandatory;
                }
            }
            if (isValueFromPipeline)
            {
                parameterFlags |= ParameterSetMetadata.ParameterFlags.ValueFromPipeline;
            }
            if (isValueFromPipelineByPropertyName)
            {
                parameterFlags |= ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName;
            }
            parameterMetadata.ParameterSets.Add(parameterSetName, new ParameterSetMetadata(position, parameterFlags, null));

            return parameterMetadata;
        }