private void SetPropertyValue(SerializationContext context, CalendarProperty property, string value) { var type = _dataTypeMapper.GetPropertyMapping(property) ?? typeof(string); var serializer = (SerializerBase)_serializerFactory.Build(type, context); using (var valueReader = new StringReader(value)) { var propertyValue = serializer.Deserialize(valueReader); var propertyValues = propertyValue as IEnumerable <string>; if (propertyValues != null) { foreach (var singlePropertyValue in propertyValues) { property.AddValue(singlePropertyValue); } } else { property.AddValue(propertyValue); } } }
public ICalendarProperty property(SerializationContext ctx, ICalendarPropertyListContainer c) //throws RecognitionException, TokenStreamException { ICalendarProperty p; { switch (LA(1)) { case IANA_TOKEN: { var n = LT(1); match(IANA_TOKEN); p = new CalendarProperty(n.getLine(), n.getColumn()) { Name = n.getText().ToUpper() }; break; } case X_NAME: { var m = LT(1); match(X_NAME); p = new CalendarProperty(m.getLine(), m.getColumn()) { Name = m.getText().ToUpper() }; break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } var processor = ctx.GetService(typeof(CompositeProcessor <ICalendarProperty>)) as CompositeProcessor <ICalendarProperty>; // Do some pre-processing on the property processor?.PreDeserialization(p); // Add the property to the container, as the parent object(s) // may be needed during deserialization. c?.Properties.Add(p); // Push the property onto the serialization context stack ctx.Push(p); IStringSerializer dataMapSerializer = new DataMapSerializer(ctx); { // ( ... )* for (;;) { if ((LA(1) == SEMICOLON)) { match(SEMICOLON); parameter(ctx, p); } else { goto _loop24_breakloop; } } _loop24_breakloop: ; } // ( ... )* match(COLON); var v = value(); // Deserialize the value of the property // into a concrete iCalendar data type, // a list of concrete iCalendar data types, // or string value. var deserialized = dataMapSerializer.Deserialize(new StringReader(v)); if (deserialized != null) { // Try to determine if this is was deserialized as a *list* // of concrete types. var targetType = dataMapSerializer.TargetType; var listOfTargetType = typeof(IList <>).MakeGenericType(targetType); if (listOfTargetType.IsInstanceOfType(deserialized)) { // We deserialized a list - add each value to the // resulting object. foreach (var item in (IEnumerable)deserialized) { p.AddValue(item); } } else { // We deserialized a single value - add it to the object. p.AddValue(deserialized); } } { // ( ... )* for (;;) { if ((LA(1) == CRLF)) { match(CRLF); } else { goto _loop26_breakloop; } } _loop26_breakloop: ; } // ( ... )* // Do some final processing on the property: processor?.PostDeserialization(p); // Notify that the property has been loaded p.OnLoaded(); // Pop the property off the serialization context stack ctx.Pop(); return(p); }