예제 #1
0
파일: Writer.cs 프로젝트: radtek/Tailviewer
 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
파일: Writer.cs 프로젝트: radtek/Tailviewer
 /// <inheritdoc />
 public void WriteAttribute(string name, ISerializableType value)
 {
     _writer.WriteStartElement(name);
     try
     {
         WriteCustomType(value);
     }
     finally
     {
         _writer.WriteEndElement();
     }
 }
예제 #4
0
파일: Reader.cs 프로젝트: ValRCS/Tailviewer
            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));
            }
예제 #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();
         }
     }
 }
예제 #6
0
 public bool TryReadAttribute(string name, out ISerializableType value)
 {
     return(TryReadAttribute <ISerializableType>(name, out value));
 }
예제 #7
0
 /// <inheritdoc />
 public bool TryReadAttribute(string name, out ISerializableType value)
 {
     return(_documentReader.TryReadAttribute(name, out value));
 }