Exemplo n.º 1
0
        public override PObject Clone()
        {
            var dict = new PDictionary();

            foreach (var kv in this)
            {
                dict.Add(kv.Key, kv.Value.Clone());
            }
            return(dict);
        }
Exemplo n.º 2
0
        void AddNewDictionaryElement(PDictionary dict)
        {
            var values = PListScheme.AvailableKeys(dict, CurrentTree);

            if (values == null)
            {
                string name = "newProperty";
                while (dict.ContainsKey(name))
                {
                    name += "_";
                }
                dict.Add(name, PObject.Create(DefaultNewObjectType));
            }
            else if (values.Any())
            {
                var value = values.FirstOrDefault();
                dict.Add(value.Identifier, value.Create());
            }
        }
Exemplo n.º 3
0
            public PObject Create()
            {
                if (Type == PDictionary.Type)
                {
                    var dictionary = new PDictionary();
                    foreach (var v in Values)
                    {
                        if (v.Required)
                        {
                            dictionary.Add(v.Identifier, v.Create());
                        }
                    }

                    // If nothing was required, create an initial one anyway
                    if (dictionary.Count == 0)
                    {
                        var first = Values.FirstOrDefault();
                        if (first == null)
                        {
                            dictionary.Add("newNode", PObject.Create(PString.Type));
                        }
                        else
                        {
                            dictionary.Add(first.Identifier ?? "newNode", first.Create());
                        }
                    }
                    return(dictionary);
                }
                else if (Type == PArray.Type)
                {
                    var array = new PArray();
                    foreach (var v in Values)
                    {
                        if (v.Required)
                        {
                            array.Add(v.Create());
                        }
                    }

                    // If nothing was required, create an initial one anyway
                    if (array.Count == 0)
                    {
                        var first = Values.FirstOrDefault();
                        if (first == null)
                        {
                            array.Add(PObject.Create(ArrayType));
                        }
                        else
                        {
                            array.Add(first.Create());
                        }
                    }
                    return(array);
                }
                else if (Values.Any())
                {
                    return(Values.First().Create());
                }
                else
                {
                    var obj = PObject.Create(Type);
                    if (!string.IsNullOrEmpty(Identifier) && !(this is Key))
                    {
                        obj.SetValue(Identifier);
                    }
                    return(obj);
                }
            }