Beispiel #1
0
        private bool ReadProperty(PropertyElement element)
        {
            if (!PropertyDefinitionLookup.TryGetValue(element.FullName, out PropertyDefinition definition))
            {
                throw new UnrecognizedPropertyException(element.FullName, element);
            }

            ElementReader.IResult <IEnumerable <object> > result =
                definition.Reader.EvaluateAndRead(element, definition, conditionalParser);

            if (result.HasValue)
            {
                VisitedProperties.Add(definition.Name);

                switch (definition)
                {
                // TODO: this logic should be in the property definitions themselves.
                case PropertyCollectionDefinition collectionDefinition:
                    if (element.Action == PropertyAction.Set)
                    {
                        collectionDefinition.ClearCollection(Properties[definition.Name]);
                    }

                    object collection = Properties[definition.Name];
                    foreach (object propertyValue in result.Value)
                    {
                        collectionDefinition.AddToCollection(collection, propertyValue);
                    }

                    break;

                case PropertyDictionaryDefinition dictionaryDefinition:
                    if (element.Action == PropertyAction.Set)
                    {
                        dictionaryDefinition.ClearDictionary(Properties[definition.Name]);
                    }

                    object dictionary = Properties[definition.Name];

                    var newValues = (Dictionary <string, object>)result.Value.First();
                    foreach (KeyValuePair <string, object> kvp in newValues)
                    {
                        dictionaryDefinition.AddToDictionary(dictionary, kvp.Key, kvp.Value);
                    }

                    break;

                default:
                    if (element.Action != PropertyAction.Set)
                    {
                        throw new InvalidPropertyActionException(element,
                                                                 "Properties that are not a collection may only set values");
                    }

                    Properties[definition.Name] = result.Value.First();
                    break;
                }
            }

            return(result.Terminate);
        }
Beispiel #2
0
 public Dictionary <string, object> GetDefaultPropertiesDictionary()
 {
     return(PropertyDefinitionLookup.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.GetOrCloneDefaultValue()));
 }