Exemple #1
0
 private void WriteCustomType(ISerializableType value)
 {
     if (value != null)
     {
         var type     = value.GetType();
         var typeName = _typeFactory.TryGetTypeName(type);
         if (typeName != null)
         {
             WriteAttribute("Type", typeName);
             _writer.WriteStartElement("Value");
             try
             {
                 value.Serialize(this);
             }
             catch (Exception e)
             {
                 Log.ErrorFormat("Caught unexpected exception while trying to serialize '{0}': {1}", value, e);
             }
             finally
             {
                 _writer.WriteEndElement();
             }
         }
         else
         {
             Log.ErrorFormat("Unable to serialize type '{0}': It has not been registered with the type factory", type);
         }
     }
 }
 private static void SerializeAndCompleteValue(
     IFieldValueCompletionContext completionContext,
     ISerializableType serializable)
 {
     try
     {
         if (TryConvertToScalarValue(
                 completionContext.Converter,
                 completionContext.Type,
                 completionContext.Value,
                 out object value))
         {
             value = serializable.Serialize(value);
             completionContext.IntegrateResult(value);
         }
         else
         {
             completionContext.ReportError(
                 "The internal resolver value could not be " +
                 "converted to a valid value of " +
                 $"`{completionContext.Type.TypeName()}`.");
         }
     }
     catch (ScalarSerializationException ex)
     {
         completionContext.ReportError(ex.Message);
     }
     catch (Exception)
     {
         completionContext.ReportError(
             "Undefined field serialization error.");
     }
 }
Exemple #3
0
 /// <inheritdoc />
 public void WriteAttribute(string name, ISerializableType value)
 {
     _writer.WriteStartElement(name);
     try
     {
         WriteCustomType(value);
     }
     finally
     {
         _writer.WriteEndElement();
     }
 }
Exemple #4
0
            public bool TryReadAttribute(string name, out ISerializableType value)
            {
                XmlElement element;

                if (!_childElements.TryGetValue(name, out element))
                {
                    value = null;
                    return(false);
                }

                return(TryReadChild(element, out value));
            }
Exemple #5
0
 private void WriteCustomType(ISerializableType value)
 {
     if (value != null)
     {
         var type     = value.GetType();
         var typeName = type.FullName;
         WriteAttribute("Type", typeName);
         _writer.WriteStartElement("Value");
         try
         {
             value.Serialize(this);
         }
         catch (Exception e)
         {
             Log.ErrorFormat("Caught unexpected exception while trying to serialize '{0}': {1}", value, e);
         }
         finally
         {
             _writer.WriteEndElement();
         }
     }
 }
Exemple #6
0
 public bool TryReadAttribute(string name, out ISerializableType value)
 {
     return(TryReadAttribute <ISerializableType>(name, out value));
 }
Exemple #7
0
 /// <inheritdoc />
 public bool TryReadAttribute(string name, out ISerializableType value)
 {
     return(_documentReader.TryReadAttribute(name, out value));
 }