Ejemplo n.º 1
0
 public void WriteDscResourceProperty(DscResourceProperty property)
 {
     WriteStartAttribute();
     Write(property.Attribute.ToString());
     if (!string.IsNullOrEmpty(property.Description))
     {
         WriteEndAttribute();
         WriteDescription(property.Description);
     }
     if (property.PossibleValues.Count > 0)
     {
         WriteValueMap(property.ValueMap);
         WriteEndAttribute();
         WriteValues(property.Values);
     }
     WriteFullEndAttribute();
     Write(" ");
     Write(DscResourceTypeConverter.ConvertToString(property.PropertyType));
     Write(" ");
     Write(property.Name);
     SemiColon();
     WriteLine();
 }
Ejemplo n.º 2
0
 public static string ToJson(DscResourceProperty o) => JsonConvert.SerializeObject(o, Converter.Settings);
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                _reader = reader;

                DscResourcePropertyCollection collection = new DscResourcePropertyCollection();

                while (Read())
                {
                    if (CurrentTokenType == JsonToken.StartObject)
                    {
                        DscResourceProperty property = new DscResourceProperty();

                        while (Read())
                        {
                            if (CurrentTokenType == JsonToken.PropertyName)
                            {
                                string name = CurrentValue.ToString();

                                switch (name)
                                {
                                case "name":
                                {
                                    property.Name = ReadString();
                                    break;
                                }

                                case "description":
                                {
                                    property.Description = ReadString();
                                    break;
                                }

                                case "attribute":
                                {
                                    string attributeValue = ReadString();
                                    property.Attribute = DscResourceAttributes.Parse(attributeValue);
                                    break;
                                }

                                case "type":
                                {
                                    string typeValue = ReadString();
                                    property.Type = DscResourceTypes.Parse(typeValue);
                                    break;
                                }

                                case "possibleValues":
                                {
                                    List <string> list = new List <string>();
                                    while (Read())
                                    {
                                        if (CurrentTokenType == JsonToken.String)
                                        {
                                            list.Add(CurrentValue.ToString());
                                        }

                                        if (CurrentTokenType == JsonToken.EndArray)
                                        {
                                            break;
                                        }
                                    }
                                    property.PossibleValues = list;
                                    break;
                                }
                                }
                            }

                            if (CurrentTokenType == JsonToken.EndObject)
                            {
                                break;
                            }
                        }

                        collection.Add(property);
                    }

                    if (CurrentTokenType == JsonToken.EndArray)
                    {
                        break;
                    }
                }
                return(collection);
            }