/// <summary> /// Tries write a formattable object in the storer. /// </summary> /// <param name="graph"> Object (or graph of objects with the given root). </param> /// <param name="type"> Type of the object. </param> /// <param name="path"> The path to the file. </param> /// <param name="storer"> The storer. </param> /// <param name="references"> Dictionary that contains references to the objects. </param> /// <returns> True if formattable objecthas been written (or is exist), otherwise false. </returns> private bool TryWriteFormattable(object graph, Type type, string path, IWriteOnlyDataStorer storer, IDictionary <object, string> references) { // Gets a formattable type for the specified type FormattableType formattableType = this.formattableTypes.FindOrDefault(f => f.IsRelatedType(type, true)); if (formattableType == null) { // If formattable type isn't exists -> type isn't supported -> returns false return(false); } // Tries write the object in the storer string className = formattableType.Name; if (this.TryWriteValue(storer, path, references, graph, className)) { formattableType.OnSerializing(graph); FormattableValue[] formattableValues = formattableType.GetValues(type); FormattableValue formattableValue; int length = formattableValues.Length; object value; Type valueType; IDictionary <string, string> values = new Dictionary <string, string>(length); for (int i = 0; i < length; i++) { formattableValue = formattableValues[i]; value = formattableValue.GetValue(graph); valueType = formattableValue.Type; if (this.IsPrimitive(valueType)) { // Value of the object is primitive - writes it in the information file values.Add(formattableValue.Name, this.GetPrimitiveConverterToString(valueType)(value)); } else { // Value of the object isn't primitive - writes it in new file try { // Tries write a value in the new file this.Write( value, StringUtils.Combine(path, formattableValue.Name, DirectorySeparatorString), storer, references ); } catch (Exception ex) { // Thrown error if value isn't optional if (!formattableValue.Optional) { throw new KeyCanNotSavedException(formattableType, formattableType.Name, ex); } } } } formattableType.OnSerialized(graph); this.WriteInfo(storer, path, className, values); } return(true); }