示例#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.");
     }
 }
示例#3
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();
         }
     }
 }